L11 Search Range in Binary Search Tree
Given two values k1 and k2 (where k1 < k2) and a root pointer to a Binary Search Tree. Find all the keys of tree in range k1 to k2. i.e. print all x such that k1<=x<=k2 and x is a key of given BST. Return all the keys in ascending order.
Example
If k1 =10
and k2 =22
, then your function should return[12, 20, 22]
.
感觉structure跟之前拿到判断是否合法BST有点像。
Last updated