We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
给定一棵二叉搜索树,请找出其中第k大的节点。
搜索二叉树的中序遍历是有序的。
class Solution { private: bool flag; int k; int res; void treeCount(TreeNode* root) { if (root == nullptr)return; treeCount(root->right); if(--k==0)res = root->val; treeCount(root->left); } public: int kthLargest(TreeNode* root, int k) { flag = false; this->k = k; treeCount(root); return res; } };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
问题
给定一棵二叉搜索树,请找出其中第k大的节点。
求解
搜索二叉树的中序遍历是有序的。
The text was updated successfully, but these errors were encountered: