leetcode/src/s0283_move_zeroes.cpp
2022-11-24 17:21:25 +08:00

21 lines
309 B
C++

#include "s0283_move_zeroes.hpp"
void Solution::moveZeroes(vector<int>& nums) {
int len = nums.size();
if (len <= 1) {
return;
}
int s{0}, f{0};
while (f < len) {
if (nums[f] != 0) {
nums[s] = nums[f];
++s;
}
++f;
}
while (s < len) {
nums[s] = 0;
++s;
}
}