leetcode/src/s0283_move_zeroes.cpp
2022-11-30 18:20:36 +08:00

21 lines
306 B
C++

#include "s0283_move_zeroes.hpp"
void S0283::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;
}
}