8000 Merge pull request #10 from advancedxy/master · likeucode/leetcode@94089f5 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 94089f5

Browse files
committed
Merge pull request soulmachine#10 from advancedxy/master
mergeTwoLists算法优化和tex文件中集合符号的修改
2 parents 60b7fbe + cb5b62f commit 94089f5

File tree

4 files changed

+19
-16
lines changed

4 files changed

+19
-16
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.log
2+
*.toc
3+
*.aux
4+
*.idx
5+
*.out
6+
leetcode-cpp.pdf

C++/chapBruteforce.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ \subsubsection{增量构造法}
134134
\subsubsection{二进制法}
135135
本方法的前提是:集合的元素不超过int位数。用一个int整数表示位向量,第$i$位为1,则表示选择$S[i]$,为0则不选择。例如\fn{S=\{A,B,C,D\}},则\fn{0110=6}表示子集\fn{\{B,C\}}。
136136

137-
这种方法最巧妙。因为它不仅能生成子集,还能方便的表示集合的并、交、差等集合运算。设两个集合的位向量分别为$B_1$$B_2$,则$B_1|B_2, B_1 \& B_2, B_1 \^ B_2$分别对应集合的并、交、对称差。
137+
这种方法最巧妙。因为它不仅能生成子集,还能方便的表示集合的并、交、差等集合运算。设两个集合的位向量分别为$B_1$$B_2$,则$B_1\cup B_2, B_1 \cap B_2, B_1 \triangle B_2$分别对应集合的并、交、对称差。
138138

139139
二进制法,也可以看做是位向量法,只不过更加优化。
140140

C++/chapSorting.tex

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,20 @@ \subsubsection{分析}
5656
\subsubsection{代码}
5757
\begin{Code}
5858
//LeetCode, Merge Two Sorted Lists
59-
// 时间复杂度O(m+n),空间复杂度O(1)
59+
// 时间复杂度O(min(m,n)),空间复杂度O(1)
6060
class Solution {
6161
public:
6262
ListNode *mergeTwoLists(ListNode *l1, ListNode *l2) {
63-
ListNode head(-1);
64-
for (ListNode* p = &head; l1 != nullptr || l2 != nullptr; p = p->next) {
65-
int val1 = l1 == nullptr ? INT_MAX : l1->val;
66-
int val2 = l2 == nullptr ? INT_MAX : l2->val;
67-
if (val1 <= val2) {
68-
p->next = l1;
69-
l1 = l1->next;
70-
} else {
71-
p->next = l2;
72-
l2 = l2->next;
73-
}
63+
if (l1 == nullptr) return l2;
64+
if (l2 == nullptr) return l1;
65+
ListNode h(-1);
66+
ListNode *p = &h;
67+
for (; l1 != nullptr && l2 != nullptr; p = p->next) {
68+
if (l1->val > l2->val) { p->next = l2; l2 = l2->next; }
69+
else { p->next = l1; l1 = l1->next; }
7470
}
75-
return head.next;
71+
p->next = l1 != nullptr ? l1 : l2;
72+
return h.next;
7673
}
7774
};
7875
\end{Code}

C++/format.cls

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ body={390pt,530pt},marginparsep=10pt,marginpar=50pt]{geometry}
5252

5353
\setlength\abovecaptionskip{0pt}
5454

55-
%\setmainfont{Times New Roman}
56-
\setmainfont{Linux Libertine O}
55+
\setmainfont{Times New Roman}
56+
%\setmainfont{Linux Libertine}
5757
%\setmainfont{TeX Gyre Pagella}
5858
\newfontfamily\urlfont{PT Sans Narrow}
5959
%\setmonofont[AutoFakeBold=1.6,AutoFakeSlant=0.17,Mapping=tex-text-tt]{Inconsolata}

0 commit comments

Comments
 (0)
0