We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 65a6697 commit f38e77bCopy full SHA for f38e77b
Split With Minimum Sum/kata.go
@@ -1,17 +1,22 @@
1
package kata
2
3
-import "sort"
+import (
4
+ "math"
5
+ "sort"
6
+)
7
8
func splitNum(num int) int {
9
if num <= 9 {
10
return num
11
}
12
- digits := make([]int, 0)
13
+ digits := make([]int, int(math.Log10(float64(num)))+1)
14
+ var i int
15
for num > 0 {
16
var digit = num % 10
17
num = num / 10
- digits = append(digits, digit)
18
+ digits[i] = digit
19
+ i++
20
21
22
if len(digits) == 2 {
0 commit comments