Thursday, December 4, 2014

Remove Duplicates from Sorted Array

    int removeDuplicates(int A[], int n) {
        if(n==0)
            return 0;
        int len=1;
        for(int i=1;i<n;i++)
        {
            if(A[i]!=A[i-1])
                A[len++]=A[i];
        }
        return len;
    }

No comments:

Post a Comment