Skip to content

Commit 5244c0b

Browse files
committed
Merge pull request soulmachine#2 from hex108/master
good catch!
2 parents 3b53a40 + 4cc6a64 commit 5244c0b

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

C++/chapLinearList.tex

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -112,22 +112,15 @@ \subsubsection{代码1}
112112
class Solution {
113113
public:
114114
int removeDuplicates(int A[], int n) {
115-
if (n == 0) return 0;
116-
117-
int occur = 1;
118-
int index = 0;
119-
for (int i = 1; i < n; i++) {
120-
if (A[index] == A[i]) {
121-
if (occur < 2) {
122-
A[++index] = A[i];
123-
occur++;
124-
}
125-
} else {
126-
A[++index] = A[i];
127-
occur = 1;
128-
}
115+
if(n <= 2) return n;
116+
117+
int index = 2;
118+
for(int i = 2; i < n; i ++){
119+
if(A[i] != A[index - 2])
120+
A[index ++] = A[i];
129121
}
130-
return index + 1;
122+
123+
return index;
131124
}
132125
};
133126
\end{Code}
@@ -241,7 +234,7 @@ \subsubsection{分析}
241234
\subsubsection{代码}
242235
\begin{Code}
243236
// LeetCode, Search in Rotated Sorted Array II
244-
// 时间复杂度O(log n),空间复杂度O(1)
237+
// 时间复杂度O(n),空间复杂度O(1)
245238
class Solution {
246239
public:
247240
bool search(int A[], int n, int target) {

0 commit comments

Comments
 (0)