7-line java solution


  • 0
    S
        public int removeElement(int[] nums, int val) {
            int count = 0;
            for(int i = 0; i < nums.length; i++)
                if(nums[i] != val)
                    nums[count++] = nums[i];
            return count;
        }
    

Log in to reply
 

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