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

Commitad6f5f1

Browse files
authored
Create 0837-new-21-game.kt
1 parentdf60136 commitad6f5f1

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

‎kotlin/0837-new-21-game.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
classSolution {
2+
funnew21Game(n:Int,k:Int,maxPts:Int):Double {
3+
if (k==0|| k+ maxPts<= n)
4+
return1.0
5+
6+
val dp=DoubleArray(k+ maxPts)
7+
var windowSum=0.0
8+
9+
for (iin k until (k+ maxPts))
10+
windowSum+=if (i<= n)1.0else0.0
11+
12+
for (iin k-1 downTo0) {
13+
dp[i]= windowSum/ maxPts
14+
windowSum+= dp[i]
15+
if (i+ maxPts<= n) {
16+
windowSum-=if (dp[i+ maxPts]!=0.0) dp[i+ maxPts]else1.0
17+
}
18+
}
19+
20+
return dp[0]
21+
}
22+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp