Python iterative DFS with a stack
\n# Definition for a binary tree node.\n# class TreeNode(object):\n#     def __init__(self, x):\n#         self.val = x\n#         self.left = None\n#         s
```\n# Definition for a binary tree node.\n# class TreeNode(object):\n#     def __init__(self, x):\n#         self.val = x\n#         self.left = None\n#         self.right = None\n\nclass Solution(object):\n    def pathSum(self, root, total):\n        """\n        :type root: TreeNode\n        :type sum: int\n        :rtype: int\n        """\n        if not root:\n            return 0\n        \n        stack = [(root, [root.val])]\n        num = 0\n        \n        while stack:\n            node, totals = stack.pop()\n            \n            num += totals.count(total)\n                \n            if node.left:\n                stack.append((node.left, [x+node.left.val for x in totals]+[node.left.val]))\n            if node.right:\n                stack.append((node.right, [x+node.right.val for x in totals]+[node.right.val]))\n        return num\n```
['Stack', 'Depth-First Search', 'Python']