Simple swap


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

Log in to reply
 

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