4 line java


  • 1
    M
        public int removeElement(int[] nums, int val) {
            int lo = 0, hi = -1;
            while(++hi<nums.length)
                if(nums[hi]!=val) nums[lo++] = nums[hi];
            return lo;
        }
    

Log in to reply
 

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