1422 - BST Problem 3 (I)   

Description

In this problem, please implement a binary search tree (BST).
You have to implement the following methods:

(1) Insert x:
      Insert an integer x into the BST if x hasn’t in the BST yet.
(2) Height x:
      Find the node x in the BST and print the height of the node in this subtree.
      If x isn't in the BST, print -1. The height of leaf is 0.

Input

For each subproblem:

(1) 1422: N <= 2000
(2) 1423: N <= 20000
(3) 1424: N <= 50000
N is the number of nodes in the tree.

Output

Sample Input  Download

Sample Output  Download

Tags




Discuss