Python Solution
What I found helps with this problem is to have two recursive functions:\n- dfs simply recurses through each node of the tree\n- find_path_from_node tries to fi
What I found helps with this problem is to have two recursive functions:\n- `dfs` simply recurses through each node of the tree\n- `find_path_from_node` tries to find paths starting from the given node\n\nI ran into problems when I tried to merge these functions into one. A lesson for me is to split up recursive functions so each recursive function has a single responsibility.\n\n\n```python\nclass Solution:\n    def pathSum(self, root: TreeNode, sum: int) -> int:\n        \n        global result\n        result = 0\n        \n        def dfs(node, target):\n            if node is None: return\n            find_path_from_node(node, target)\n            dfs(node.left, target)\n            dfs(node.right, target)\n                \n        def find_path_from_node(node, target):\n            global result\n            if node is None: return\n            if node.val == target: result += 1\n            find_path_from_node(node.left, target-node.val)\n            find_path_from_node(node.right, target-node.val)\n            \n        dfs(root, sum)\n        \n        return result\n```
['Python', 'Python3']