给定一棵二叉搜索树,请找出其中的第k小的TreeNode结点。
/*
public class TreeNode {
int val = 0;
TreeNode left = null;
TreeNode right = null;
public TreeNode(int val) {
this.val = val;
}
}
*/
public class Solution {
int count = 0;
TreeNode node;
TreeNode KthNode(TreeNode pRoot, int k){
if(k == 0) return null;
NodePring(pRoot , k);
return node;
}
void NodePring(TreeNode pRoot, int k){
if(pRoot == null) return ;
if(k == count) return ;
KthNode(pRoot.left, k);
count ++;
if(count== k) node = pRoot;
KthNode(pRoot.right, k);
}
}