题目描述: 主要思路: 想要将树遍历存在数组里,然后排序后找到第k小的元素 后来得知 二叉搜索树的中序遍历是升序,于是不需要排序可以直接找了 代码实现: int count=0; int ans; public int kthSmallest(TreeNode root, int k) { if(root == null){ return 0; } kthSmallest(root.left,k); count++; if(count == k){ ans = root.val; }else{ kthSmallest(root.right,k); } return ans; }