05 August 2008
Given a Binary Search Tree and a target number, return true if there exist two elements in the BST such that their sum is equal to the given target.
Example 1:
1
2
3
4
5
6
7
8
9
10
Input:
5
/ \
3 6
/ \ \
2 4 7
Target = 9
Output: True
Example 2:
1
2
3
4
5
6
7
8
9
10
Input:
5
/ \
3 6
/ \ \
2 4 7
Target = 28
Output: False
在BST中寻找是否有两个nodes的val,它们相加的和等于target,返回true,否则返回false。
这道题实际上是关于Tree而不是Array,参见这里。