8000 add 441 solution · reverse/awesome-golang-leetcode@9c3b944 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9c3b944

Browse files
committed
add 441 solution
1 parent 06a4fb8 commit 9c3b944

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/0441.Arranging-Coins/Solution.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
package Solution
22

3-
func Solution(x bool) bool {
4-
return x
3+
import "math"
4+
5+
func arrangeCoins(n int) int {
6+
if n <= 0 {
7+
return 0
8+
}
9+
10+
x := math.Sqrt(2*float64(n)+0.25) - 0.5
11+
return int(x)
512
}

src/0441.Arranging-Coins/Solution_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,17 @@ func TestSolution(t *testing.T) {
1010
// 测试用例
1111
cases := []struct {
1212
name string
13-
inputs bool
14-
expect bool
13+
inputs int
14+
expect int
1515
}{
16-
{"TestCase", true, true},
17-
{"TestCase", true, true},
18-
{"TestCase", false, false},
16+
{"TestCase", 5, 2},
17+
{"TestCase", 8, 3},
1918
}
2019

2120
// 开始测试
2221
for i, c := range cases {
2322
t.Run(c.name+" "+strconv.Itoa(i), func(t *testing.T) {
24-
got := Solution(c.inputs)
23+
got := arrangeCoins(c.inputs)
2524
if !reflect.DeepEqual(got, c.expect) {
2625
t.Fatalf("expected: %v, but got: %v, with inputs: %v",
2726
c.expect, got, c.inputs)

0 commit comments

Comments
 (0)
0