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 };
2023-11-20 10:54:28
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 };