题解 | #寻找第K大#

寻找第K大

https://www.nowcoder.com/practice/e016ad9b7f0b45048c58a9f27ba618bf

#include <bits/stdc++.h>

class Solution {
public:
    int findKth(vector<int> a, int n, int K) {
        // write code here
        priority_queue<int> mq;

        for(int i = 0; i<n; ++i)
        {
            mq.push(a[i]);
        }

        int t;
        for(int i=0; i<K; i++)
        {
            t = mq.top();

            mq.pop();

            
        }

        return t;
    }
};

利用了堆 空间O(n) 时间O(n)

全部评论

相关推荐

2025-12-13 14:51
已编辑
井冈山大学 算法工程师
龙虾x:算法比你强的没有你美,比你美的…..算了已经没有比你美的了
工作两年想退休了
点赞 评论 收藏
分享
迷茫的大四🐶:都让开,我tm来啦
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务