Simple solution with C++


  • 1
    S
    class Solution {
    public:
        int removeDuplicates(int A[], int n) {
            int j=0;
            if(0 == n)
                return 0;
            if(1 == n)
                return 1;
            A[0] = A[0];
            for(int i=1; i<n; i++) {
                if(A[i] != A[j])
                    A[++j] = A[i];
            }
            return j+1;
        }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.