Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.
Note:
You may assume k is always valid, 1 ≤ k ≤ BST’s total elements.
Example 1:
1 | Input: root = [3,1,4,null,2], k = 1 |
Example 2:
1 | Input: root = [5,3,6,2,4,null,null,1], k = 3 |
Analyzation:
Time complexity should be O(H+k)
where H=log(N)
stands for the height of the tree and k
stands
Solution:
Iterative solution:
Pending…