class Solution {
public:
int removeDuplicates(int A[], int n) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int len = 0;
int time = 1;
for(int i = 0; i < n; i++){
if(i+1 < n && A[i] == A[i+1]){
time++;
}else{
time = 1;
}
if(time >= 3){
len++;
}else{
A[i-len] = A[i];
}
}
return n-len;
}
};
[leetcode]Remove Duplicates from Sorted Array II
最新推荐文章于 2015-02-01 20:18:16 发布