My code:
public class Solution {
public void moveZeroes(int[] nums) {
if (nums == null || nums.length == 0)
return;
int del = 0;
for (int i = 0; i < nums.length; i++) {
if (nums[i] == 0) {
del++;
}
else {
nums[i - del] = nums[i];
}
}
for (int i = nums.length - del; i < nums.length; i++)
nums[i] = 0;
}
}
没什么难的。但是提交了好几次才过。不可原谅!!
注意,要按照原顺序移动!!
Anyway, Good luck, Richardo!