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

Commitb3bec83

Browse files
authored
Create 0877-stone-game.kt
1 parent9fc2f4d commitb3bec83

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

‎kotlin/0877-stone-game.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
classSolution {
2+
funstoneGame(piles:IntArray):Boolean {
3+
val dp=Array(piles.size) {IntArray(piles.size) {-1 } }
4+
5+
fundfs(left:Int,right:Int):Int {
6+
if (left> right)
7+
return0
8+
if (dp[left][right]!=-1)
9+
return dp[left][right]
10+
11+
val isEven= (right- left)%2==0
12+
dp[left][right]= maxOf(
13+
dfs(left+1, right)+if (isEven) piles[left]else0,
14+
dfs(left, right-1)+if (isEven) piles[right]else0
15+
)
16+
17+
return dp[left][right]
18+
}
19+
20+
return dfs(0, piles.lastIndex)> (piles.sum()?:0)/2
21+
}
22+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp