Move Zeros
Description
Input: [0,1,0,3,12]
Output: [1,3,12,0,0]Solutions
My solution
class Solution {
public:
void moveZeroes(vector<int>& nums) {
int n = nums.size();
for(int i = 0, j = 0; i < n; ++i){
if(nums[i] != 0){
swap(nums[i], nums[j]);
++j;
}
}
}
};Longer but possibly faster solution
Last updated