思路:将非0数移动到前面,后面的直接用0赋值
代码:
class Solution {
public:
void moveZeroes(vector<int>& nums) {
int slow = 0;
for(int fast = 0 ; fast <nums.size(); fast++)
{
if(nums[fast] != 0 )
nums[slow++] = nums[fast];
}
while(slow < nums.size())
nums[slow++] = 0;
}
};