题目描述
Given a Binary Search Tree. The task is to find the minimum valued element in this given BST.
Example 1:
Input:
5
/ \
4 6
/ \
3 7
/
1
Output: 1
Example 2:
Input:
9
\
10
\
11
Output: 9
Your Task:
The task is to complete the function minValue() which takes root as the argument and returns the minimum element of BST. If the tree is empty, there is no minimum element, so return -1 in that case.
Expected Time Complexity: O(Height of the BST)
Expected Auxiliary Space: O(1).
Constraints:
0 <= N <= 10^{4}
输入格式
见题面
输出格式
见题面
样例输入
5
/ \
4 6
/ \
3 7
/
1
样例输出
1