Skip to content

Commit f38e77b

Browse files
committed
2578. Split With Minimum Sum v3
1 parent 65a6697 commit f38e77b

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Split With Minimum Sum/kata.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
package kata
22

3-
import "sort"
3+
import (
4+
"math"
5+
"sort"
6+
)
47

58
func splitNum(num int) int {
69
if num <= 9 {
710
return num
811
}
912

10-
digits := make([]int, 0)
13+
digits := make([]int, int(math.Log10(float64(num)))+1)
14+
var i int
1115
for num > 0 {
1216
var digit = num % 10
1317
num = num / 10
14-
digits = append(digits, digit)
18+
digits[i] = digit
19+
i++
1520
}
1621

1722
if len(digits) == 2 {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy