1 class Solution { 2 public: 3 void moveZeroes(vector<int>& nums) { 4 int j = 0; 5 for(int i = 0; i< nums.size(); ++i){ 6 if(nums[i] != 0) nums[j++] = nums[i]; 7 } 8 for(int i = j; i<nums.size(); ++i){ 9 nums[i] = 0; 10 } 11 } 12 };
原文:http://www.cnblogs.com/onlyac/p/5132890.html