21 lines
309 B
C++
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;
|
||
|
}
|
||
|
}
|