Simple Python Solution: top-down DFS + DP
Please see and vote for my solutions for these similar problems.\n\n257. Binary Tree Paths\n\n    def binaryTreePaths(self, root: TreeNode) -> List[str]:\n     
Please see and vote for my solutions for these similar problems.\n\n[257. Binary Tree Paths](https://leetcode.com/problems/binary-tree-paths/discuss/309004/Different-DFS-Python-solutions)\n```\n    def binaryTreePaths(self, root: TreeNode) -> List[str]:\n        def dfs(node, path, res):\n            if node.left == None and node.right == None:\n                res.append(path + str(node.val))\n            if node.left:\n                dfs(node.left, path + str(node.val) + \'->\', res)\n            if node.right:\n                dfs(node.right, path + str(node.val) + \'->\', res)\n        \n        if not root:\n            return []\n        res = []\n        dfs(root, "", res)\n        return res\n```\n\n[129. Sum Root to Leaf Numbers](https://leetcode.com/problems/sum-root-to-leaf-numbers/discuss/328123/Simple-Python-Solution%3A-top-down-DFS)\n```\n    def sumNumbers(self, root: TreeNode) -> int:\n        def dfs(node, bits, res):\n            if node.left == None and node.right == None:\n                res[0] += int(bits + str(node.val), 10)\n            if node.left:\n                dfs(node.left, bits + str(node.val), res)\n            if node.right:\n                dfs(node.right, bits + str(node.val), res)\n        \n        if root == None:\n            return 0\n        bits, res = \'\', [0]\n        dfs(root, bits, res)\n        return res[0]\n```\n\n[1022. Sum of Root To Leaf Binary Numbers](https://leetcode.com/problems/sum-of-root-to-leaf-binary-numbers/discuss/328033/Top-down-Python-DFS-Solution)\n```\n    def sumRootToLeaf(self, root: TreeNode) -> int:\n        def dfs(node, bits, res):\n            if node.left == None and node.right == None:\n                res[0] += int(bits + str(node.val), 2)\n            if node.left:\n                dfs(node.left, bits + str(node.val), res)\n            if node.right:\n                dfs(node.right, bits + str(node.val), res)\n        \n        if root == None:\n            return 0\n        bits, res = \'\', [0]\n        dfs(root, bits, res)\n        return res[0]\n```\n\n[988. Smallest String Starting From Leaf](https://leetcode.com/problems/smallest-string-starting-from-leaf/discuss/328119/Simple-Python-Solution%3A-top-down-DFS)\n```\n    def smallestFromLeaf(self, root: TreeNode) -> str:\n        def dfs(root, s):\n            s = s + chr(ord(\'a\') + root.val)\n            if not root.left and not root.right:\n                if res[0] == None:\n                    res[0] = s[::-1]\n                else:\n                    res[0] = min(res[0], s[::-1])\n            if root.left:\n                dfs(root.left, s)\n            if root.right:\n                dfs(root.right, s)\n        \n        if not root:\n            return \'\'\n        res = [None]\n        dfs(root, \'\')\n        return res[0]\n```\n\n[112. Path Sum](https://leetcode.com/problems/path-sum/discuss/328124/Simple-Python-Solution%3A-top-down-DFS)\n\n```\n    def hasPathSum(self, root: TreeNode, s: int) -> bool:\n        def dfs(root, curr_s):\n            curr_s += root.val\n            if not root.left and not root.right:\n                if curr_s == s:\n                    res[0] = True\n                    return\n            if not res[0] and root.left:\n                dfs(root.left, curr_s)\n            if not res[0] and root.right:\n                dfs(root.right, curr_s)\n        \n        if not root:\n            return False\n        res = [False]\n        dfs(root, 0)\n        return res[0]\n```\n\n[113. Path Sum II](https://leetcode.com/problems/path-sum-ii/discuss/328125/Simple-Python-Solution%3A-top-down-DFS)\n```\n    def pathSum(self, root: TreeNode, s: int) -> List[List[int]]:\n        def dfs(root, lst, curr_s):\n            curr_s += root.val\n            if not root.left and not root.right:\n                if curr_s == s:\n                    res.append(lst + [root.val])\n                    return\n            if root.left:\n                dfs(root.left, lst + [root.val], curr_s)\n            if root.right:\n                dfs(root.right, lst + [root.val], curr_s)\n        \n        if not root:\n            return []\n        res = []\n        dfs(root, [], 0)\n        return res\n```\n\n[437. Path Sum III](https://leetcode.com/problems/path-sum-iii/discuss/328128/Simple-Python-Solution%3A-top-down-DFS-%2B-DP) (Similar problem: 560. Subarray Sum Equals K)\n\n```\n    def pathSum(self, root, s):\n        def dfs(root, curr_s):\n            curr_s += root.val\n            res[0] += pre_sums.get(curr_s - s, 0)\n            pre_sums[curr_s] = pre_sums.get(curr_s, 0) + 1\n            if root.left:\n                dfs(root.left, curr_s)\n            if root.right:\n                dfs(root.right, curr_s)\n            pre_sums[curr_s] -= 1\n            if pre_sums[curr_s] == 0:\n                del pre_sums[curr_s]\n        \n        res = [0]\n        pre_sums = {0: 1}\n        if not root:\n            return res[0]\n        dfs(root, 0)\n        return res[0]\n```
[]