Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // zeroes to right
- void move_zeroes(vector<int> &arr) {
- int i = 0;
- for(auto el : arr) {
- if (el != 0) {
- arr[i++] = el;
- }
- }
- for(int k = i; k < arr.size())
- arr[k] = 0;
- }
- // zeroes to left
- void move_zeroes(vector<int> &arr) {
- int i = arr.size() - 1;
- for(int el = arr.size(); el >= 0; el--) {
- if (arr[el] != 0)
- arr[i--] = arr[el];
- }
- for(int k = i; k >= 0; --k)
- arr[k] = 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement