class Solution {
public:
int removeDuplicates(int A[], int n) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if(n==0)
return 0;
if(n==1)
return 1;
int i=0,j=1;
while(j<n){
if(A[i]==A[j])
++j;
else {
A[++i]=A[j++];
}
}
return i+1;
}
};
Leetcode: Remove Duplicates from Sorted Array
最新推荐文章于 2022-04-06 16:22:53 发布