二叉搜索树的第k个节点
2017-02-21 19:44
274 查看
给定一颗二叉搜索树,请找出其中的第k大的结点。例如, 5 / \ 3 7 /\ /\ 2 4 6 8 中,按结点数值大小顺序第三个结点的值为4。
递归搜索
递归搜索
/* public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(int val) { this.val = val; } } */ public class Solution { private int num = 0 ; TreeNode KthNode(TreeNode pRoot, int k){ if(k == 0)return null ; if(pRoot == null)return null ; TreeNode re = KthNode(pRoot.left , k) ; if(re != null)return re ; num++ ; if(num == k)return pRoot ; return KthNode(pRoot.right , k) ; } }
相关文章推荐
- 剑指offer_二叉搜索树的第k个节点
- 二叉搜索树的第k个节点
- 【剑指offer】题63:二叉搜索树的第k个节点
- 剑指Offer--二叉搜索树的第K个节点-不会
- 二叉搜索树的第K个节点:递归中用参数返回值。
- 二叉搜索树的第K个节点
- 面试题63:二叉搜索树的第K个节点
- 从二叉搜索树的第k个节点问题看递归如何返回普通变量和对象
- 剑指offer----二叉搜索树的第K个节点----java实现
- 求二叉搜索树中第k个节点
- 二叉搜索树的第k个节点
- 剑指offer-二叉搜索树的第K个节点
- 62、二叉搜索树的第K个节点
- 二叉搜索树的第K个节点
- 剑指offer面试题63:二叉搜索树的第k个节点 Java实现
- 剑指offer——二叉搜索树的第k个节点
- 二叉搜索树的第K个节点
- Python:二叉搜索树的第k个节点
- 二叉搜索树的第k个节点(java版)
- 二叉搜索树的第k个节点