We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 19caa17 commit 7287754Copy full SHA for 7287754
1 file changed
leetcode/src/binary_trees/lc_653_two_sum_IV/two_sum.py
@@ -0,0 +1,25 @@
1
+
2
+def two_sum_bst(root, target):
3
+ def two_sum_helper(node):
4
+ if node is None:
5
+ return False
6
7
+ diff = target - node.val
8
+ if diff in value_map:
9
+ return True
10
11
+ value_map[node.val] = diff
12
13
+ left = two_sum_helper(node.left)
14
+ if left:
15
+ return left
16
17
+ right = two_sum_helper(node.right)
18
+ if right:
19
+ return right
20
21
22
23
24
+ value_map = {}
25
+ return two_sum_helper(root)
0 commit comments