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;
for(int i = 1; i < n; i++){
if(A[i] == A[i-1]){
len++;
}else{
A[i-len] = A[i];
}
}
return n-len;
}
};
[leetcode]Remove Duplicates from Sorted Array
最新推荐文章于 2022-04-06 16:22:53 发布