2022-05-17
Description
Input: nums = [0,1,0,3,12]
Output: [1,3,12,0,0]Input: nums = [0]
Output: [0]Solution
func moveZeroes(nums []int) {
for i, j := 0, 0; j < len(nums); {
if nums[j] != 0 {
nums[i], nums[j] = nums[j], nums[i]
i++
}
j++
}
}Description
Solution
Approach #0
Approach #1
Last updated