283.283. Move Zeroes
283. Move Zeroes
Solution
public class Solution {
public void moveZeroes(int[] nums) {
if (nums == null || nums.length == 0) return;
int end = 0;
int start = 1;
while (start < nums.length) {
if (nums[start] == 0 ) {
if (nums[end] != 0) {
end = start;
}
} else {
if (nums[end] == 0) {
change(nums, start, end);
end++;
}
}
start++;
}
}
public void change(int[] nums, int m, int n) {
int temp = nums[m];
nums[m] = nums[n];
nums[n] = temp;
}
}Last updated