SHARE
TWEET

Untitled

a guest Apr 18th, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // zeroes to right
  2. void move_zeroes(vector<int> &arr) {
  3.   int i = 0;
  4.   for(auto el : arr) {
  5.     if (el != 0) {
  6.       arr[i++] = el;
  7.     }
  8.   }
  9.   for(int k = i; k < arr.size())
  10.     arr[k] = 0;
  11. }
  12.  
  13. // zeroes to left
  14. void move_zeroes(vector<int> &arr) {
  15.   int i = arr.size() - 1;
  16.   for(int el = arr.size(); el >= 0; el--) {
  17.     if (arr[el] != 0)
  18.       arr[i--] = arr[el];
  19.   }
  20.   for(int k = i; k >= 0; --k)
  21.     arr[k] = 0;
  22. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top