K-th Smallest Number In BST
Given the root node of a valid BST and a number k
, return the k
th smallest number
in this BST (1-indexed).
Input
bst
: a binary tree representing the existing BST.k
: an integer.
Output
The k
th smallest number in bst
.
Examples
Example 1:
Input:
1bst = <See explanation> 2k = 4
Output: 6
Explanation:
Constraints
1 <= k <= n <= 10^5
, wheren
is the size ofbst
.
Try it yourself
Solution
Title
Script
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem
Ipsum
has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
Contrary to popular belief, Lorem
Ipsum
is not simply random text.
1 >>> a = [1, 2, 3] 2 >>> a[-1] 3 3