My Java Solution


  • 0
    public static int removeElement(int[] a, int val) {
            int len = a.length, i = len-1;
            while(i >= 0){
              if(a[i] == val){ 
                len--; // reduce size of array
              }
              i--;
            }
            return len; // return the new size after removing
        } 
    

Log in to reply
 

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