/*
public class TreeNode {
int val = 0;
TreeNode left = null;
TreeNode right = null;
public TreeNode(int val) {
this.val = val;
}
}
*/
public class Solution {
private int index=1;
private TreeNode ans=null;
TreeNode KthNode(TreeNode pRoot, int k)
{
MidSearch(pRoot,k);
return ans;
}
public void MidSearch(TreeNode pRoot, int k){
if(pRoot==null)
return ;
MidSearch(pRoot.left,k);
if(k==index)
ans=pRoot;
index++;
MidSearch(pRoot.right,k);
}
}
利用二叉树中序遍历递归即可。