leetcode/src/s0283_move_zeroes.cpp

21 lines
306 B
C++
Raw Normal View History

2022-11-24 09:21:25 +00:00
#include "s0283_move_zeroes.hpp"
2022-11-30 10:20:36 +00:00
void S0283::moveZeroes(vector<int>& nums) {
2022-11-24 09:21:25 +00:00
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;
}
}