//思路:
//利用二次搜索树的中序遍历性质
private TreeNode res;
private int cnt;
TreeNode KthNode(TreeNode pRoot, int k) {
if(pRoot==null){
return null;
}
inOrder(pRoot,k);
return res;
}
private void inOrder(TreeNode pRoot,int k){
if(pRoot==null){
return;
}
inOrder(pRoot.left,k);
cnt++;
if(cnt==k){
res = pRoot;
return;
}
inOrder(pRoot.right,k);
}
https://www.mianshi.online,https://www.i9code.cn
本文由博客一文多发平台 OpenWrite 发布!
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。