剑指 Offer 54. 二叉搜索树的第k大节点 - 力扣(LeetCode) (leetcode-cn.com)
class Solution {
vector<int>temp;
public:
int kthLargest(TreeNode* root, int k) {
fun(root);
int l=temp.size();
return temp[l-k];
}
void fun(TreeNode*root){
if(root==nullptr) return;
fun(root->left);
temp.push_back(root->val);
fun(root->right);
}
};