forked from shruti170901/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMove Zeroes.cpp
More file actions
37 lines (35 loc) · 703 Bytes
/
Copy pathMove Zeroes.cpp
File metadata and controls
37 lines (35 loc) · 703 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
class Solution {
public:
void swap(int& i,int& j){
int temp=i;
i=j;
j=temp;
}
void moveZeroes(vector<int>& nums) {
int size=nums.size();
int i=0,j=1;
while(i<size-1&&j<size){
if(nums[i]!=0 && nums[j]!=0){
i++;j++;
continue;
}
if(nums[i]==0)
{
if(nums[j]==0)
j++;
else{
swap(nums[i],nums[j]);
i++;
j++;
}
}
else{
if(nums[j]==0)
{
i++;
j++;
}
}
}
}
};