9. Move Zeros
30 Jun 2020 | Daily Algorithms
class Solution {
public:
void moveZeroes(vector<int>& nums) {
int i=0;
vector<int> Copy;
for(int n : nums)
{
if(n!=0)
{
Copy.push_back(n);
}
else if(n==0)
{
i++;
}
}
for(int a=0; a<i;a++)
{
Copy.push_back(0);
}
nums = Copy;
}
};
class Solution {
public:
void moveZeroes(vector<int>& nums) {
int i=0;
vector<int> Copy;
for(int n : nums)
{
if(n!=0)
{
Copy.push_back(n);
}
else if(n==0)
{
i++;
}
}
for(int a=0; a<i;a++)
{
Copy.push_back(0);
}
nums = Copy;
}
};
Comments