Skip to content

Commit ec525e9

Browse files
author
openset
committed
Add: Integer Break
1 parent cabf520 commit ec525e9

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

internal/leetcode/problems_status.go

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ var problemStatus = map[int]bool{
9797
319: true,
9898
326: true,
9999
342: true,
100+
343: true,
100101
344: true,
101102
345: true,
102103
350: true,
+12
Original file line numberDiff line numberDiff line change
@@ -1 +1,13 @@
11
package problem343
2+
3+
func integerBreak(n int) int {
4+
if n <= 3 {
5+
return n - 1
6+
}
7+
ans := 1
8+
for n > 4 {
9+
n -= 3
10+
ans *= 3
11+
}
12+
return ans * n
13+
}
Original file line numberDiff line numberDiff line change
@@ -1 +1,39 @@
11
package problem343
2+
3+
import "testing"
4+
5+
type testType struct {
6+
in int
7+
want int
8+
}
9+
10+
func TestIntegerBreak(t *testing.T) {
11+
tests := [...]testType{
12+
{
13+
in: 2,
14+
want: 1,
15+
},
16+
{
17+
in: 10,
18+
want: 36,
19+
},
20+
{
21+
in: 3,
22+
want: 2,
23+
},
24+
{
25+
in: 7,
26+
want: 12,
27+
},
28+
{
29+
in: 17,
30+
want: 486,
31+
},
32+
}
33+
for _, tt := range tests {
34+
got := integerBreak(tt.in)
35+
if got != tt.want {
36+
t.Fatalf("in: %v, got: %v, want: %v", tt.in, got, tt.want)
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)