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

Commit f9844bd

Browse files
Create Solution.py
1 parent ddec5ad commit f9844bd

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

‎Stone Game VII/Solution.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution:
2+
def stoneGameVII(self, stones: List[int]) -> int:
3+
N = len(stones)
4+
dpCurr, dpLast = [0] * N, [0] * N
5+
for i in range(N - 2, -1, -1):
6+
total = stones[i]
7+
dpLast, dpCurr = dpCurr, dpLast
8+
for j in range(i + 1, N):
9+
total += stones[j]
10+
dpCurr[j] = max(total - stones[i] - dpLast[j], total - stones[j] - dpCurr[j-1])
11+
return dpCurr[-1]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /