Skip to content

Commit

Permalink
Time: 18 ms (61.79%), Space: 6.7 MB (91.15%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
hovanhoa committed Sep 27, 2024
1 parent 58e77d9 commit bd9e5f9
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions 0283-move-zeroes/0283-move-zeroes.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
func moveZeroes(nums []int) {
idx := 0
for i := 0; i < len(nums); i ++ {
if nums[i] != 0 {
nums[i], nums[idx] = nums[idx], nums[i]
idx ++
count := 0
for _, v := range nums {
if v != 0 {
nums[count] = v
count++
}
}

for count < len(nums) {
nums[count] = 0
count++
}
}

0 comments on commit bd9e5f9

Please sign in to comment.