Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. class Solution:
  2.     def stoneGameIII(self, stoneValue: List[int]) -> str:
  3.        
  4.         from functools import lru_cache
  5.         @lru_cache(maxsize=None)
  6.         def getScore(i):            
  7.             if i == len(stoneValue):
  8.                 return 0
  9.             best = float('-inf')
  10.             score = 0
  11.             for j in range(3):
  12.                 if i + j == len(stoneValue):
  13.                     break
  14.                 x = stoneValue[i + j]
  15.                 score += x
  16.                 best = max(best, score - getScore(i + j + 1))
  17.             return best
  18.            
  19.            
  20.         total = sum(stoneValue)
  21.         diff = getScore(0)
  22.         if diff == 0:
  23.             return "Tie"
  24.         if diff > 0:
  25.             return "Alice"
  26.         return "Bob"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement