Python dfs iteration + recursion w/comments
py\n# Definition for a binary tree node.\n# class TreeNode:\n#     def __init__(self, val=0, left=None, right=None):\n#         self.val = val\n#         self.l
```py\n# Definition for a binary tree node.\n# class TreeNode:\n#     def __init__(self, val=0, left=None, right=None):\n#         self.val = val\n#         self.left = left\n#         self.right = right\n\'\'\'\nw: tree traversal + greedy\nh: the node x partiton the tree into three parts:\n    1: its left subtree\n    2: its right right subtree\n    3: its parent and the other subtree of its parent\n    in order to win the game, we should have as many as blue node, so we do it greedily:\n    color x\'s parent or x\'left child or x\'s right child to block x\n    \n    so if there is a partition which contains more node than the other two, we will win\n\'\'\'\nclass Solution:\n    def btreeGameWinningMove(self, root: TreeNode, n: int, x: int) -> bool:\n        # 1. find x\n        stack = []\n        node = root\n        x_node = None\n        while stack or node:\n            while node:\n                if node.val == x:\n                    x_node = node\n                stack.append(node)\n                node = node.left\n            \n            node = stack.pop()\n            if node.val == x:\n                x_node = node\n            node = node.right\n        \n        \n        # 2. count the three partition\n        def dfs(node, cnt):\n            if not node:\n                return 0\n            cnt[0] += 1\n            dfs(node.left, cnt)\n            dfs(node.right, cnt)\n        \n        p1 = [0]\n        p2 = [0]\n        dfs(x_node.left, p1)\n        dfs(x_node.right, p2)\n        \n        remain = n - p1[0] - p2[0] - 1\n        \n        if remain > p1[0] + p2[0] + 1 or p1[0] > remain + p2[0] + 1 or p2[0] > remain + p1[0] + 1:\n            return True\n        else:\n            return False\n```
['Depth-First Search', 'Python']