← 返回 ibm 的题目列表Search Values in a Binary Search Tree
类型:online_judge
Write a function to determine, for each value in a given list of integers, if it is present in a binary search tree. Return 1 if it is present, otherwise return 0.
Function Description:
Function isPresent has the following parameters:
BSTreeNode root: reference to the root node of a tree of integers
int val[q]: an array of integer items to search for Returns:
int[q]: an integer array where each value at index i indicates whether val[i] is found in the BST.
Constraints:
1 ≤ n, q ≤ 10^5
1 ≤ val[i] ≤ 5×10^4
Properties of a binary search tree: Each node holds a value and a reference to as many as 2 child nodes. The root node has no ancestors. The children are called left and right, and subtrees rooted at left and right are the left and right subtrees. Each node's value in its left subtree must be less than its own value, and each node in its right subtree must have a greater or equal value to the root. This allows for efficient searching.
Provide test cases and sample input/output.
Example
Input
7 4 15