Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def stoneGameIII(self, stoneValue: List[int]) -> str:
- from functools import lru_cache
- @lru_cache(maxsize=None)
- def getScore(i):
- if i == len(stoneValue):
- return 0
- best = float('-inf')
- score = 0
- for j in range(3):
- if i + j == len(stoneValue):
- break
- x = stoneValue[i + j]
- score += x
- best = max(best, score - getScore(i + j + 1))
- return best
- total = sum(stoneValue)
- diff = getScore(0)
- if diff == 0:
- return "Tie"
- if diff > 0:
- return "Alice"
- return "Bob"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement