class Solution {
public:
void moveZeroes(vector<int>& nums) {
int index = 0, cnt = 0;
while (cnt < (nums.size())) {
if (nums[index] == 0){
for (int i = index; i < nums.size(); i++) {
if (nums[i] == 0) {
for (int j = i; j < nums.size() - 1; j++) {
swap(nums, j, j + 1);
}
}
}
} else {
index++;
}
cnt ++;
}
}
private:
void swap(vector<int>& nums, int num1, int num2) {
int tmp = nums[num1];
nums[num1] = nums[num2];
nums[num2] = tmp;
}
};
class Solution {
public:
void moveZeroes(vector<int>& nums) {
int write = 0;
for (int i=0; i<nums.size(); i++) {
if (nums[i] != 0) {
nums[write++] = nums[i];
}
}
for (; write<nums.size(); write++) {
nums[write] = 0;
}
}
};