Time 100% and Memory 100%
Intuition\nNotice that the difference of scores is the sum of all the stones that Bob takes, so for both Alice and Bob, their optimal strategy is to minimize th
# Intuition\nNotice that the difference of scores is the sum of all the stones that Bob takes, so for both Alice and Bob, their optimal strategy is to minimize their own sums of stones.\n\n# Approach\nUse dynamic programming from the last step to the first.\n\n# Complexity\n- Time complexity:\n$O(n^2)$\n\n- Space complexity:\n$O(n)$\n\n# Code\n```\nclass Solution:\n    def stoneGameVII(self, stones: List[int]) -> int:\n        n = len(stones)\n        flag = 1\n        lis = list(stones)\n        for i in range(1,n):\n            for j in range(n - i):\n                if flag:\n                    lis[j] = max(lis[j],lis[j+1])\n                else:\n                    lis[j] = min(lis[j] + stones[j + i],lis[j+1] + stones[j])\n            flag ^= 1\n            #print(lis)\n        return lis[0] if not flag else sum(stones) - lis[0]\n        \n```
['Python3']