move-zeroes 1.0.0
Move Zeroes
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1#include <bits/stdc++.h>
2
3using namespace std;
4
6{
7public:
8 void moveZeroes(vector<int>& nums)
9 {
10 int index = 0;
11 for (int el: nums)
12 if (el != 0)
13 nums[index++] = el;
14 while (index < (int)nums.size())
15 nums[index++] = 0;
16 }
17};
18
19int main()
20{
21 vector<int> nums = {0,1,0,3,12};
22 Solution().moveZeroes(nums);
23 for (int el: nums)
24 cout << el << " ";
25 cout << '\n';
26 return 0;
27}
void moveZeroes(vector< int > &nums)
Definition main.cpp:8
int main()
Definition main.cpp:19