Search in BST
Easyjavapythonccppjavascript
Given a Binary Search Tree and a target value, determine whether the value is present.
The BST is given in level order: M tokens, each an integer or null; the first token is the root.
Input Format
The first line contains an integer M. The second line contains M space-separated tokens (integers or null). The third line contains the integer target.
Output Format
Print 1 if target is present, otherwise print 0.
Example 1
Input
7 8 3 10 1 6 null 14 6
Output
1
Explanation: 6 is in the left subtree of 8.
- 1 <= number of nodes <= 5000
- All node values are distinct.
- -1000000000 <= value, target <= 1000000000