Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.
Note:
1. You must do this in-place without making a copy of the array.
2. Minimize the total number of operations.
Example 1
Input: [0,1,0,3,12]
Output: [1,3,12,0,0]
var moveZeroes = function(nums) {
for(let i = nums.length - 1; i >= 0; i--){
if(!nums[i]){
nums.splice(i,1);
nums.push(0);
}
}
return nums;
};
위와 같이 풀이하고 배열도 copy하였지만 음,,, 맞는 방법인지는 모르겠다 ㅜ