Skip to content

Commit 997d6ba

Browse files
author
openset
committed
Add: 2 Keys Keyboard
1 parent c6daca4 commit 997d6ba

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,13 @@
11
package p_2_keys_keyboard
2+
3+
func minSteps(n int) int {
4+
if n == 1 {
5+
return 0
6+
}
7+
for i := 2; i < n; i++ {
8+
if n%i == 0 {
9+
return i + minSteps(n/i)
10+
}
11+
}
12+
return n
13+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,31 @@
11
package p_2_keys_keyboard
2+
3+
import "testing"
4+
5+
type caseType struct {
6+
input int
7+
expected int
8+
}
9+
10+
func TestMinSteps(t *testing.T) {
11+
tests := [...]caseType{
12+
{
13+
input: 3,
14+
expected: 3,
15+
},
16+
{
17+
input: 30,
18+
expected: 10,
19+
},
20+
{
21+
input: 97,
22+
expected: 97,
23+
},
24+
}
25+
for _, tc := range tests {
26+
output := minSteps(tc.input)
27+
if output != tc.expected {
28+
t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected)
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)