Easy understanding accepted Java solution


  • 0
    X
    public class Solution {
        public void moveZeroes(int[] nums) {
            int n = nums.length;
            int j = 0;
            for(int i = 0; i < n; i++) {
                if(nums[i] != 0) 
                    nums[j++] = nums[i];
            }
            for(; j < n; j++) {
                nums[j] = 0;
            }
            return;
        }
    }
    

Log in to reply
 

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