We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3b53a40 commit 3068c0cCopy full SHA for 3068c0c
C++/chapLinearList.tex
@@ -112,22 +112,16 @@ \subsubsection{代码1}
112
class Solution {
113
public:
114
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
127
- occur = 1;
128
+ if(n <= 2)
+ return n;
+
+ int index = 2;
+ for(int i = 2; i < n; i ++){
+ if(A[i] != A[index - 2])
+ A[index ++] = A[i];
129
}
130
- return index + 1;
+ return index;
131
132
};
133
\end{Code}
0 commit comments