FAST AND IN ORDER JAVA


  • 0
    K
    public int removeElement(int[] nums, int val) {
            if (nums==null||nums.length==0) return 0;
            int count=0,n=nums.length,index=0;
            while (count<n&&index<n){
                if (nums[index]!=val) nums[count++]=nums[index++];
                else index++;
            }
            return count;
        }
    

Log in to reply
 

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