Skip to content

Commit 942838a

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

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

Python/stone-game-v.py

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

21-
max_score = 0
2221
for l in xrange(2, n+1):
2322
for i in xrange(n-l+1):
2423
j = i+l-1
@@ -35,7 +34,7 @@ def stoneGameV(self, stoneValue):
3534
max_score = max(max_score, dp[j][p])
3635
dp[i][j] = max(dp[i][j-1], (prefix[j+1]-prefix[i]) + max_score)
3736
dp[j][i] = max(dp[j][i+1], (prefix[j+1]-prefix[i]) + max_score)
38-
return max_score
37+
return dp[0][n-1]-(prefix[n]-prefix[0])
3938

4039

4140
# Time: O(n^2)

0 commit comments

Comments
 (0)