Last active
April 9, 2019 08:26
-
-
Save Fly-Style/ef40f8ed0ec53288644689012fd547b2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment