Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save toliuweijing/6147731 to your computer and use it in GitHub Desktop.
Save toliuweijing/6147731 to your computer and use it in GitHub Desktop.
class Solution {
public:
int removeDuplicates(int A[], int n) {
auto C = A;
int len = 0;
for (int i = 0 ; i < n ; ++i) {
if (len >= 2 && C[len-1] == C[len-2] && A[i] == C[len-1]) continue;
C[len++] = A[i];
}
return len;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment