Skip to content

Commit d89074a

Browse files
authored
Update stone-game-v.py
1 parent 942838a commit d89074a

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Python/stone-game-v.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def stoneGameV(self, stoneValue):
1818
for i in xrange(n):
1919
dp[i][i] = stoneValue[i]
2020

21+
max_score = 0
2122
for l in xrange(2, n+1):
2223
for i in xrange(n-l+1):
2324
j = i+l-1
@@ -34,7 +35,7 @@ def stoneGameV(self, stoneValue):
3435
max_score = max(max_score, dp[j][p])
3536
dp[i][j] = max(dp[i][j-1], (prefix[j+1]-prefix[i]) + max_score)
3637
dp[j][i] = max(dp[j][i+1], (prefix[j+1]-prefix[i]) + max_score)
37-
return dp[0][n-1]-(prefix[n]-prefix[0])
38+
return max_score
3839

3940

4041
# Time: O(n^2)

0 commit comments

Comments
 (0)