tanchukw

Untitled

Oct 7th, 2015
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     void moveZeroes(vector<int>& nums) {
  4.         int sz = nums.size();
  5.         for (int i = sz - 2; i >= 0;  --i)
  6.         {
  7.             if (!nums[i])
  8.             {
  9.                 int t = i;
  10.                 while (t < sz - 1 && nums[t + 1])
  11.                 {
  12.                     nums[t + 1] += nums[t];
  13.                     nums[t] = nums[t + 1] - nums[t];
  14.                     nums[t + 1] -= nums[t];
  15.                     ++t;
  16.                 }
  17.             }
  18.         }
  19.         return;
  20.     }
  21. };
Advertisement
Add Comment
Please, Sign In to add comment