simple intuitive Java


  • 0
    J
        public void moveZeroes(int[] nums) {
            int cnt = 0;
            for (int i = 0; i < nums.length; i++) {
                int num = nums[i];
                if (num == 0) cnt++; 
                else if (cnt > 0) {
                    nums[i - cnt] = nums[i];
                    nums[i] = 0;
                }
            }
        }
    

Log in to reply
 

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