My simple C++ solution using O(n) time


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

Log in to reply
 

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