Remove Duplicates from Sorted Array

    int removeDuplicates(int A[], int n) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
        if(n == 0)
            return n;
        int i;
        int result = 0;
        for(i = 1; i < n; i++){
            if(A[i] != A[result]){
                A[result+1] = A[i];
                result++;
            }
        }
        return result+1;
    }

 

posted on 2013-09-22 20:58  waruzhi  阅读(135)  评论(0编辑  收藏  举报

导航