[Python] Clear DFS Solution with Video Explanation
Video with clear visualization and explanation:\nhttps://youtu.be/MwLSDvmkGGY\n\n\n\nIntuition: dfs+memo\n\n\nCode\nInspired by https://leetcode.com/problems/st
Video with clear visualization and explanation:\nhttps://youtu.be/MwLSDvmkGGY\n\n\n\nIntuition: dfs+memo\n\n\n**Code**\nInspired by https://leetcode.com/problems/stone-game-vii/discuss/970268/C%2B%2BPython-O(n-*-n)\n```\nfrom itertools import accumulate\n\nclass Solution:\n    def stoneGameVII(self, stones: List[int]) -> int:\n        n = len(stones)\n        memo = [[0]*n for _ in range(n)]\n        sums = [0]+list(accumulate(stones))\n        \n        def dfs(l, r) -> int:\n            if l == r: return 0\n            if memo[l][r] == 0:\n                range_sum = sums[r+1]-sums[l]\n                memo[l][r] = max(range_sum-stones[l]-dfs(l+1, r), range_sum-stones[r]-dfs(l, r-1))\n                \n            return memo[l][r]\n        \n        res = dfs(0, n-1)\n        return res\n```\n\nTime: O(n*n)\n\n\nFeel free to subscribe to my channel. More LeetCoding videos coming up!
['Python']