230. Kth Smallest Element in a BST
Given the root of a binary search tree, and an integer k, return the kth smallest value (1-indexed) of all the values of the nodes in the tree.
DFS搜索,遍历的时候更新全局变量count。
采用中序搜索,当count等于k时,将全局变量ans设置为root.val。
搜索完毕返回ans。
1 | /** |
230. Kth Smallest Element in a BST
https://xuanhe95.github.io/2022/04/18/230-Kth-Smallest-Element-in-a-BST/