Skip to content

Commit c64c7a7

Browse files
author
openset
committed
Add: Bulb Switcher
1 parent 4e1f1e0 commit c64c7a7

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

internal/leetcode/problems_status.go

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ var problemStatus = map[int]bool{
9494
290: true,
9595
292: true,
9696
303: true,
97+
319: true,
9798
326: true,
9899
342: true,
99100
344: true,
+7-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
package bulb_switcher
1+
package problem_319
2+
3+
import "math"
4+
5+
func bulbSwitch(n int) int {
6+
return int(math.Sqrt(float64(n)))
7+
}
+31-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,31 @@
1-
package bulb_switcher
1+
package problem_319
2+
3+
import "testing"
4+
5+
type caseType struct {
6+
input int
7+
expected int
8+
}
9+
10+
func TestBulbSwitch(t *testing.T) {
11+
tests := [...]caseType{
12+
{
13+
input: 3,
14+
expected: 1,
15+
},
16+
{
17+
input: 4,
18+
expected: 2,
19+
},
20+
{
21+
input: 5,
22+
expected: 2,
23+
},
24+
}
25+
for _, tc := range tests {
26+
output := bulbSwitch(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)