首页 > 其他 > 详细

378. 有序矩阵中第K小的元素

时间:2020-04-27 10:26:31      阅读:58      评论:0      收藏:0      [点我收藏+]
 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 };

 

378. 有序矩阵中第K小的元素

原文:https://www.cnblogs.com/yuhong1103/p/12784742.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!