class Solution {
public void moveZeroes(int[] nums) {
if (nums == null || nums.length == 0) return;
int slow = 0;
for(int fast=0;fast<nums.length;fast++){
if(nums[fast]!=0){
int temp = nums[slow];
nums[slow]=nums[fast];
nums[fast]=temp;
slow++;
}
}
}
}设置两个指针(slow与fast)进行遍历
slow指针指向下一个非零元素存放的位置
fast指针负责遍历数组
当遍历到数组不为0时使用temp交换当前位置位置不为0的值,然后slow位置加一