875. Search in Binary Search Tree

EasyTreesBSTBinary Search

Given the root of a binary search tree and a target value, determine whether the target exists in the BST. Return true or false. Exploit the BST property to search in O(h) time. The input gives a level-order BST array and the target separated by ' | '.

Input: A level-order BST array and the target, separated by ' | '.

Output: Boolean — true or false.

Examples

Example 1
Input: [8,3,10,1,6,null,14] | 6
Output: true
Explanation: 6 is present.
Example 2
Input: [8,3,10,1,6,null,14] | 9
Output: false
Explanation: 9 is absent.
Example 3
Input: [5] | 5
Output: true
Explanation: Single matching node.

Constraints

Asked by

GoogleMetaAmazonMicrosoftBloomberg
Solve this problem in the editor →