一次遍历,j相当于遍历到第一个零元素,将其和非零元素i交换,
使用的是leetcode题解的动图

class Solution {
public:
void moveZeroes(vector<int>& nums) {
int n = nums.size();
int j = 0;
for (int i = 0; i < n; ++i) {
if (nums[i] != 0) {
swap(nums[i], nums[j]);
++j;
}
}
}
};
自己的解法中一定要注意数组的越界问题!!!











![完美的输出打印 SQL 及执行时长[MyBatis-Plus系列]](https://img-blog.csdnimg.cn/img_convert/2f2356937db21222bc8858daf57b2793.png)





