LeetCode 230. 二叉搜索树中第K小的元素 230. 二叉搜索树中第K小的元素解题思路对于二叉搜索树来说,中序遍历就是从小到大遍历节点值,所以遍历到第 k 个节点即是答案 参考代码12345678910111213141516171819202122class Solution { private int res; private int k; public int kthSmallest(TreeNode root, int k) { this.k = k; dfs(root); return res; } private void dfs(TreeNode node) { if(node == null || k < 0) { return; } dfs(node.left); if(k > 0) { k --; res = node.val; } dfs(node.right); }} LeetCode #树 #深度优先搜索 #二叉树 #二叉搜索树 LeetCode 230. 二叉搜索树中第K小的元素 https://sowink.cn/2026/02/08/LeetCode-230-二叉搜索树中第K小的元素/ 作者 Xurx 发布于 2026年2月8日 许可协议 LeetCode 23. 合并 K 个升序链表 上一篇 LeetCode 234. 回文链表 下一篇 Please enable JavaScript to view the comments