leetcode283 C++ 40ms 移除0
class Solution {
public:
void moveZeroes(vector<int>& nums) {
if(nums.empty() || nums.size() == 1){
return;
}
auto slow = nums.begin();
auto fast = slow +1;
int temp;
while(slow < fast && fast != nums.end()){
while(*slow!=0){
slow++;
if(slow == nums.end()){
return;
}
}
fast = slow + 1;
if(fast == nums.end()){
return;
}
while(*fast == 0){
fast++;
if(fast == nums.end()){
return;
}
}
temp = *slow;
*slow = *fast;
*fast = temp;
slow++;
fast++;
}
}
};