-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path283.move-zeroes.cpp
More file actions
36 lines (29 loc) · 850 Bytes
/
283.move-zeroes.cpp
File metadata and controls
36 lines (29 loc) · 850 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
class Solution {
public:
void print(vector<int> & nums){
for(auto i: nums)
cout<<i<<" ";
cout<<endl;
}
void moveZeroes(vector<int>& nums) {
if (nums.size() == 1)
return;
int count = 0;
int zero = nums.size()-1;
while(zero>=0 && !nums[zero]) zero--;
for(int i = 0 ; i<=zero; i++){
if(!nums[i]){
int temp = i;
// cout<<"zero found at pos : "<<i<<endl;
while(temp != nums.size()-1){
nums[temp] = nums[temp+1];
temp++;
}
nums[nums.size()-1] = 0;
zero--;
i--;
// print(nums);
}
}
}
};