283. 移动零

 1 class Solution 
 2 {
 3 public:
 4     void moveZeroes(vector<int>& nums) 
 5     {
 6         int n = nums.size();
 7         int begin = 0;
 8         for(int i = 0;i < n;i ++)
 9         {
10             if(nums[i]) swap(nums[i],nums[begin++]);
11         }
12     }
13 };

 

上一篇:leetcode_283_移动零


下一篇:leetcode 283. 移动零