Python. ||  one traverse, 9 lines   ||   T/S:  91% / 93%
Here\'s the plan:\n\n- We use the function dfs to traverse each node\'s subtree and return the maximum level in the subtree.\n- We determine whether dfs(node.le
###### Here\'s the plan:\n\n- We use the function `dfs` to traverse each node\'s subtree and return the maximum level in the subtree.\n- We determine whether `dfs(node.left) == dfs(node.right)`; if so, then node is a candidate for the answer. \n- We store the most recent candidate node in `d` by `key = maxLevel`\nfor the subtree. \n- We return the actual maximum level as `d[dfs(root)]`.\n\n```\nclass Solution:\n    def subtreeWithAllDeepest(self, root: TreeNode) -> TreeNode:\n                               \n        def dfs(node = root, level = 0):\n            if not node:\n                return level-1\n            \n            l, r = dfs(node.left, level+1), dfs(node.right, level+1)\n            \n            if l == r:\n                d[l] = node\n                \n            return max(l,r)\n        \n        d = {}\n        return d[dfs()]\n```\n\n[https://leetcode.com/problems/smallest-subtree-with-all-the-deepest-nodes/submissions/1272760997/](https://leetcode.com/problems/smallest-subtree-with-all-the-deepest-nodes/submissions/1272760997/)\n\nI could be wrong, but I think that time complexity is *O*(*N*) and space complexity is *O*(*N*), in which *N* ~ the number of nodes.\n\n\n\n
['Python']