
算法分析:
- 如果数组没有0,快慢指针同步移动,元素会被自己复制;
- 如果有0,快指针找到非零元素,将其复制到慢指针位置
- 最终将剩余位置填充为0。
代码:
class Solution {
public void moveZeroes(int[] nums) {
int len = nums.length;
int slow = 0;
int fast = 0;
while(fast < len){
if(nums[fast] != 0){
nums[slow++] = nums[fast];
}
fast++;
}
while(slow < len){
nums[slow++] = 0;
}
}
}


![[PICO VR眼镜]眼动追踪串流Unity开发与使用方法,眼动追踪打包报错问题解决(Eye Tracking/手势跟踪)](https://i-blog.csdnimg.cn/direct/63442aacb4c548288c3041b3de670fe9.png)
















