-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path144MoveZeroes.cpp
More file actions
43 lines (38 loc) · 791 Bytes
/
Copy path144MoveZeroes.cpp
File metadata and controls
43 lines (38 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include<vector>
#include<iostream>
using namespace std;
class Solution {
public:
void moveZeroes(vector<int>& nums) {
int start = 0;
for(auto x : nums){
if(x != 0){
nums[start++] = x;
}
}
for(int i = start; i < nums.size(); i++){
nums[i] = 0;
}
cout<<"swaped 0s : ";
for(auto x : nums){
cout<<x<<" ";
}
}
};
int main(){
Solution obj;
vector<int> nums = {0,1,0,3,12};
obj.moveZeroes(nums);
return 0;
}
/*
void moveZeroes(vector<int>& nums) {
int j = 0;
for (int i = 0; i < nums.size(); i++) {
if (nums[i] != 0) {
swap(nums[i], nums[j]);
j++;
}
}
}
*/