中序遍历搜索二叉树,为有序数组
class Solution {
int target;
int count = 1;
int res;
public int kthSmallest(TreeNode root, int k) {
this.target=k;
rec(root);
return res;
}
public void rec(TreeNode node){
if(node == null) return;
rec(node.left);
// System.out.println("count"+count+" "+"node"+node.val);
if(count==target) {
res = node.val;
count++;
return;
}
count++;
rec(node.right);
}
}