cpp-interview/Problems/LeetcodeProblems/283-move-zeroes.h

12 lines
372 B
C
Raw Normal View History

2018-02-09 21:47:58 +08:00
class Solution {
public:
void moveZeroes(vector<int>& nums) {
int left = 0, right = 0;
for(; left < nums.size() && nums[left] != 0; left++);
for(right = left; right < nums.size(); right++) {
if(nums[right] == 0) continue;
nums[left++] = nums[right];
}
while(left < nums.size()) nums[left++] = 0;
}
};