My c solution 7ms


  • 1
    B
    int removeDuplicates(int A[], int n) {
        if (n < 2) return n;
        int pos = 2;
        int prev2, prev = A[0];
        for (int i = 2; i < n; ++i) {
            prev2 = prev;
            prev = A[i - 1];
            if (prev2 != A[i] || prev != A[i]) {
                A[pos++] = A[i];
            }
        }
        return pos;
    }

Log in to reply
 

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