Simple Java solution


  • 0
    L
     public void moveZeroes(int[] nums) {
          for(int i=0,j=0;i<nums.length;i++) {
                if(nums[i]!=0) {
                    int temp = nums[j];
                    nums[j] = nums[i];
                    nums[i] = temp;
                    j++;
                }
            }
    

Log in to reply
 

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