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

Commit 656b8a8

Browse files
committed
989 wrong answer
1 parent 32079dc commit 656b8a8

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
11
package problem0989
22

3+
import "strconv"
4+
35
func addToArrayForm(A []int, K int) []int {
6+
a := slice2num(A)
7+
a += K
8+
return num2Slice(a)
9+
}
10+
11+
func slice2num(A []int) int {
12+
res := 0
13+
for _, v := range A {
14+
res = res*10 + v
15+
}
16+
return res
17+
}
418

5-
return nil
19+
func num2Slice(n int) []int {
20+
s := strconv.Itoa(n)
21+
bytes := []byte(s)
22+
res := make([]int, len(bytes))
23+
for i, b := range bytes {
24+
res[i] = int(b - '0')
25+
}
26+
return res
627
}

Algorithms/0989.add-to-array-form-of-integer/add-to-array-form-of-integer_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ var tcs = []struct {
1313
ans []int
1414
}{
1515

16+
{
17+
[]int{1, 2, 6, 3, 0, 7, 1, 7, 1, 9, 7, 5, 6, 6, 4, 4, 0, 0, 6, 3},
18+
516,
19+
[]int{1, 2, 6, 3, 0, 7, 1, 7, 1, 9, 7, 5, 6, 6, 4, 4, 0, 5, 7, 9},
20+
},
21+
1622
{
1723
[]int{1, 2, 0, 0},
1824
34,

0 commit comments

Comments
 (0)