C++ accepted solution. O(n) constant space


  • 0
    M
    int removeElement(int A[], int n, int elem) {
        int count = 0;
        for(int i = 0; i < n; i++)
        {
            if(A[i] == elem)
            {
                continue;
            }
            
            A[count] = A[i];
            count++;
        }
        
        return count;
    }

Log in to reply
 

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