题目
My way
递归中序遍历,输出对应元素
1 | /** |
因为二叉搜索树的中序遍历结果是由小到大的,所以输出第k-1
个元素即可
大力王way
递归,控制中序遍历到第k-1
个元素
1 | /** |
References
https://leetcode-cn.com/problems/kth-smallest-element-in-a-bst/solution/c-zhong-xu-bian-li-ti-jie-by-da-li-wang/
Just a Blog
1 | /** |
因为二叉搜索树的中序遍历结果是由小到大的,所以输出第k-1
个元素即可
k-1
个元素1 | /** |
https://leetcode-cn.com/problems/kth-smallest-element-in-a-bst/solution/c-zhong-xu-bian-li-ti-jie-by-da-li-wang/