首页 > 代码库 > Remove Duplicates from Sorted Array

Remove Duplicates from Sorted Array

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;
    }
};

Remove Duplicates from Sorted Array