Move Zeroes
ID: 283; easy
Solution 1
func moveZeroes(nums []int) {
for i := 0; i < len(nums)-1; i++ {
j := i
if nums[i] == 0 {
for j++; j < len(nums)-1 && nums[j] == 0; j++ {}
nums[i], nums[j] = nums[j], nums[i]
}
}
}Solution 2
Last updated
Was this helpful?