classSolution{int n =0;int ans =-1;publicintkthLargest(TreeNode root,int k){if(root ==null|| k <1|| k < n){return ans;}kthLargest(root.right,k);
n++;if(n == k){
ans = root.val;return ans;}kthLargest(root.left,k);return ans;}}
剑指 Offer 54. 二叉搜索树的第k大节点描述给定一棵二叉搜索树,请找出其中第k大的节点。class Solution { int n = 0; int ans = -1; public int kthLargest(TreeNode root, int k) { if(root == null || k < 1 || k < n){ return ans; } kthLargest(ro