Advertisement
bbescos

Untitled

Jan 28th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.28 KB | None | 0 0
  1.     // Run-time complexity O(n)
  2.     // Memory complexity O(1)
  3.     void moveZeroes(vector<int>& nums) {
  4.         int pos0 = 0;
  5.         for (int i = 0; i < nums.size(); ++i) {
  6.             if (nums[i] != 0) {
  7.                 swap(nums[i], nums[pos0++]);
  8.             }
  9.         }
  10.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement