一、题目内容
二、题解
解法1:
思路
二叉搜索树,中序遍历则为从小到大,中序遍历的倒叙,则为从大到小
代码
class Solution {private int currIndex = 0;private int res;public int kthLargest(TreeNode root, int k) {currIndex = k;recur(root);return res;}private void recur(TreeNode root){if(root == null){return;}recur(root.right);if(currIndex == 0){return;}if(--currIndex == 0) {res = root.val;}recur(root.left);}}
