This is the simplest in java I guess


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

Log in to reply
 

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