O(N) 0ms Java Solution


  • 0
    W
    public void moveZeroes(int[] nums) {
            if(nums.length == 0) return;
            int count = 0;
            int s = 0;
            for(int i = 0;i<nums.length;i++){
                if(nums[i] !=0 ){
                        nums[s] = nums[i];
                        s++;
                }
                if(nums[i] == 0) count++;
            }
            int d = nums.length - count;
            while(d < nums.length){
                nums[d] = 0;
                d++;
            }
        }
    

Log in to reply
 

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