0ms easy to understand Java solution


  • 8
    S
    public class Solution {
        public void moveZeroes(int[] nums) {
            if(nums == null || nums.length < 1) return;
            int count = 0;
            int numslength = nums.length;
            for(int i=0; i<numslength; i++) {
                if(nums[i] != 0) {
                    nums[count] = nums[i];
                    count++;
            }
        }
        
        int numofzeros = numslength - count;
        for(int i=0; i<numofzeros; i++) nums[count + i] = 0;
    }
    

    }


Log in to reply
 

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