class Solution {
public:
int removeDuplicates(int A[], int n) {
int duplicate = 0;
int i = 0;
for(i = 0; i < n - 1; i++){
if(A[i] == A[i + 1]){
duplicate++;
} else {
A[i - duplicate + 1] = A[i + 1];
}
}
return n - duplicate;
}
};
Leetcode Remove Duplicates from Sorted Array
最新推荐文章于 2022-04-06 16:22:53 发布