【剑指Offer】二叉搜索树的第k个结点 Posted on 2017-09-08 | In Algorithm , 剑指Offer 题目给定一棵二叉搜索树,请找出其中的第k大的结点。 实现123456789public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(int val) { this.val = val; }} 12345678910111213141516171819202122232425262728private int count = 0;public TreeNode KthNode(TreeNode pRoot, int k) { if (pRoot == null || k < 1) return null; return KthNodeHelper(pRoot, k);}private TreeNode KthNodeHelper(TreeNode root, int k) { if (root == null) return null; TreeNode node = KthNodeHelper(root.left, k); if (node != null) return node; if (++count == k) return root; node = KthNodeHelper(root.right, k); if (node != null) return node; return null;}