1 static int wing=[]() 2 { 3 std::ios::sync_with_stdio(false); 4 cin.tie(NULL); 5 return 0; 6 }(); 7 8 class Solution 9 { 10 public: 11 void moveZeroes(vector<int>& nums) 12 { 13 int sz=nums.size(); 14 int i=0,j=0; 15 while(j<sz) 16 { 17 if(nums[j]!=0) 18 nums[i++]=nums[j]; 19 j++; 20 } 21 while(i<sz) 22 nums[i++]=0; 23 return ; 24 } 25 };
类似数组中删除元素,后面的往前放,右指针扫描完后,左指针把剩下的所有值置为0即可。