Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit65a3f12

Browse files
author
Kyle Liu
authored
Merge pull request6boris#150 from kylesliu/develop
add 441 solution
2 parents32f0575 +9c3b944 commit65a3f12

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-
funcSolution(xbool)bool {
4-
returnx
3+
import"math"
4+
5+
funcarrangeCoins(nint)int {
6+
ifn<=0 {
7+
return0
8+
}
9+
10+
x:=math.Sqrt(2*float64(n)+0.25)-0.5
11+
returnint(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
namestring
13-
inputsbool
14-
expectbool
13+
inputsint
14+
expectint
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
fori,c:=rangecases {
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)

[8]ページ先頭

©2009-2025 Movatter.jp