We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 57cdfd7 commit 6288dbcCopy full SHA for 6288dbc
data_structures/binary_tree/data_structures/binary_tree/binary_tree_path_sum.py
@@ -1 +1,22 @@
1
+ class Solution:
2
+ def pathSum(self, root: TreeNode, sum: int) -> int:
3
4
+ global result
5
+ result = 0
6
+
7
+ def dfs(node, target):
8
+ if node is None: return
9
+ find_path_from_node(node, target)
10
+ dfs(node.left, target)
11
+ dfs(node.right, target)
12
13
+ def find_path_from_node(node, target):
14
15
16
+ if node.val == target: result += 1
17
+ find_path_from_node(node.left, target-node.val)
18
+ find_path_from_node(node.right, target-node.val)
19
20
+ dfs(root, sum)
21
22
+ return result
0 commit comments