We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 010a59c commit 879d2ecCopy full SHA for 879d2ec
my-submissions/m1214.py
@@ -0,0 +1,30 @@
1
+# Definition for a binary tree node.
2
+# class TreeNode:
3
+# def __init__(self, val=0, left=None, right=None):
4
+# self.val = val
5
+# self.left = left
6
+# self.right = right
7
+class Solution:
8
+ def twoSumBSTs(self, root1: Optional[TreeNode], root2: Optional[TreeNode], target: int) -> bool:
9
+ bst2 = set()
10
+ nxt = [root2]
11
+ while nxt :
12
+ curr = nxt.pop()
13
+ bst2.add(curr.val)
14
+ if curr.left :
15
+ nxt.append(curr.left)
16
+ if curr.right :
17
+ nxt.append(curr.right)
18
+
19
+ nxt = [root1]
20
21
22
+ if target - curr.val in bst2 :
23
+ return True
24
25
26
27
28
29
30
+ return False
0 commit comments