Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit 5112689

Browse files
committed
1089 wrong answer
1 parent 135b45b commit 5112689

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed
Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,27 @@
11
package problem1089
22

3-
func duplicateZeros(arr []int) {
3+
func duplicateZeros(A []int) {
4+
n := len(A)
5+
//
6+
i, count := 0, 0
7+
for i+count < n {
8+
if A[i] == 0 {
9+
count++
10+
}
11+
i++
12+
}
13+
i--
14+
//
15+
j := n - 1
16+
for count > 0 {
17+
if A[i] == 0 {
18+
A[j-1], A[j] = 0, 0
19+
j -= 2
20+
count--
21+
} else {
22+
A[j] = A[i]
23+
j--
24+
}
25+
i--
26+
}
427
}

Algorithms/1089.duplicate-zeros/duplicate-zeros_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ var tcs = []struct {
1212
ans []int
1313
}{
1414

15+
{
16+
[]int{0, 0, 0, 0, 0, 0, 0},
17+
[]int{0, 0, 0, 0, 0, 0, 0},
18+
},
19+
1520
{
1621
[]int{1, 0, 2, 3, 0, 4, 5, 0},
1722
[]int{1, 0, 0, 2, 3, 0, 0, 4},

0 commit comments

Comments
 (0)