一 题目:

二 代码:
public class KthSmallest230 {
int k=0;
Integer res=null;
public int kthSmallest(TreeNode root, int k) {
this.k=k;
//二叉搜索树,左小右大
//由于中序遍历就是在从小到大遍历节点值,所以遍历到的第 k 个节点值就是答案。
search(root);
return res;
}
//中序遍历,每次找到一个要打印的数就计1
private void search(TreeNode cur) {
if (cur==null){
return;
}
search(cur.left);
if (--k==0){
this.res=cur.val;
return;
}
search(cur.right);
}
}