#653
Two Sum IV - Input is a BST
pupil · 345 · lc easy +22 · verified · 63.1% accepted · 7,261 likes · top 65%
Description
Given the root of a binary search tree and a target integer k, determine whether any two distinct nodes in the BST sum to k. Return true if such a pair exists, false otherwise.
Example 1:
Input: root = [5,3,6,2,4,null,7], k = 9
Output: true
Example 2:
Input: root = [5,3,6,2,4,null,7], k = 28
Output: false
Code
1
2
3
4
5
6
7
8
9