Accepted C Solution -> 2ms


  • 1
    A
    int last = n-1;
    int cur = 0;
    int count = 0;
    
    while(last > cur)
    {
        if(A[cur] != elem)
            cur++;
        else{
            if(A[last] == elem)
            {
                last--;
                count++;
            }
            else
            {
                A[cur++] = A[last--];
                count++;
            }
        }
    }
    
    if(last == cur && A[last] == elem)
        count ++;
    
    return n - count;

Log in to reply
 

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