1690. Stone Game VII
On This Page
class Solution:
def stoneGameVII(self, stones: List[int]) -> int:
s = list(accumulate(stones, initial=0))
n = len(stones)
f = [[0] * n for _ in range(n)]
for i in range(n - 2, -1, -1):
for j in range(i + 1, n):
a = s[j + 1] - s[i + 1] - f[i + 1][j]
b = s[j] - s[i] - f[i][j - 1]
f[i][j] = max(a, b)
return f[0][-1]