Sum of Two Numbers in BSTs
You are given two binary search trees a
and b
and an integer target
. Return whether there’s a number in a
and a number in b
such that their sum equals to target
Constraints
n ≤ 100,000
wheren
is the number of nodes ina
m ≤ 100,000
wherem
is the number of nodes inb
https://binarysearch.com/problems/Sum-of-Two-Numbers-in-BSTs
Examples
Example 1
Input
- a =
- b =
- target =
9
Output
- answer =
True
Explanation
We can pick 7
from a
and 2
from b
.
Example 2
Input
- a =
- b =
- target =
4
Output
- answer =
False
Leave a comment