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 d5605f6 commit d1a213fCopy full SHA for d1a213f
C++/LeetCodet题解(C++版).pdf
849 Bytes
C++/chapLinearList.tex
@@ -115,6 +115,25 @@ \subsubsection{代码}
115
};
116
\end{Code}
117
118
+下面是一个更简洁的版本。上面的代码略长,不过扩展性好一些,例如将\fn{occur < 2}改为\fn{occur < 3},就变成了允许重复最多3次。
119
+\begin{Code}
120
+// LeetCode, Remove Duplicates from Sorted Array II
121
+// @author hansonyu (http://weibo.com/u/1666779725)
122
+class Solution {
123
+public:
124
+ int removeDuplicates(int A[], int n) {
125
+ int index = 0;
126
+ for (int i = 0; i < n; ++i) {
127
+ if (i > 0 && i < n - 1 && A[i] == A[i - 1] && A[i] == A[i + 1])
128
+ continue;
129
+
130
+ A[index++] = A[i];
131
+ }
132
+ return index;
133
134
+};
135
+\end{Code}
136
137
138
\subsubsection{相关题目}
139
0 commit comments