Java solution simple


  • 1
    public void moveZeroes(int[] nums) {
            int indx = 0;
            for(int num: nums){
                if(num != 0){
                    nums[indx] = num;
                    indx++;
                }
            }
            
            for(int i=indx; i<nums.length; i++){
                nums[i] = 0;
            }
        }
    

Log in to reply
 

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