Can anybody please tell me what's wrong with that code ? the breaking test case is [2,2,3] , 3


  • 0
    N

    public int removeElement(int[] A, int elem)
    {

    if (A.length ==0)
     
    {
         return 0;
     }
     else
     {
         int i =0;
         int j = A.length-1;
        
         while (i<=j)
         {
             while(j>=0 && A[j]==elem)
             {
                 j--;
             }
             if(A[i]==elem && j>=0)
             {
                 A[i]=A[j];
                 i++;
                 j--;
             
             }
             else 
             {
                 i++;
             }
         }
         return j+1;
     }
    

    }


Log in to reply
 

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