题解 | #寻找第K大#
寻找第K大
https://www.nowcoder.com/practice/e016ad9b7f0b45048c58a9f27ba618bf
class Solution { public: int findKth(vector<int> a, int n, int K) { // write code here priority_queue<int,vector<int>,greater<int>> q; for(int i=0;i<K;i++) { q.push(a[i]); } for(int j=K;j<n;j++) { if(q.top()<a[j]) { q.pop(); q.push(a[j]); } } return q.top(); } };