root of a binary search tree: for every node, all values in its left subtree are smaller than its value and all values in its right subtree are larger. All values in the tree are distinct.
Check whether the tree has two different nodes whose values add up to goal. Return True if such a pair exists, otherwise False.root=tree_node([10, 4, 15, 1, 7, None, 20]), goal=22 → True
7 + 15 = 22, and both values are in the tree.
root=tree_node([10, 4, 15, 1, 7, None, 20]), goal=20 → False
20 = 10 + 10, but there is only one node with value 10 and a node cannot be used twice. No other pair works.
root=tree_node([3]), goal=6 → False
Node.val ≤ 10⁴root is a valid binary search treeroot=tree_node([10, 4, 15, 1, 7, None, 20]), goal=22
True
Run checks the first 3 tests in your browser. Submit checks all 72 tests on the server, hidden ones included.