378. 有序矩阵中第K小的元素
作者:互联网
1 class Solution 2 { 3 public: 4 int kthSmallest(vector<vector<int>>& matrix, int k) 5 { 6 priority_queue<int,vector<int>,greater<int>> pq; 7 int n = matrix.size(); 8 for(int i = 0;i < n;i ++) 9 { 10 for(int j = 0;j < n;j ++) pq.push(matrix[i][j]); 11 } 12 while(--k && !pq.empty()) pq.pop(); 13 return pq.top(); 14 } 15 };
标签:&&,pq,matrix,int,矩阵,++,pop,378,有序 来源: https://www.cnblogs.com/yuhong1103/p/12784742.html