leetcode :Binary Search:Kth Smallest Element in a Sorted Matrix(378)
来源:互联网 发布:淘宝宝贝详情编辑器 编辑:程序博客网 时间:2024/06/15 22:24
Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix.
Note that it is the kth smallest element in the sorted order, not the kth distinct element.
matrix = [ [ 1, 5, 9], [10, 11, 13], [12, 13, 15]],k = 8,return 13.
class Solution {public: int kthSmallest(vector<vector<int>>& matrix, int k) { priority_queue<int, vector<int>> q; for (int i = 0; i < matrix.size(); ++i) { for (int j = 0; j < matrix[i].size(); ++j) { q.emplace(matrix[i][j]); if (q.size() > k) q.pop(); } } return q.top(); }};
0 0
- leetcode :Binary Search:Kth Smallest Element in a Sorted Matrix(378)
- Binary Search:378. Kth Smallest Element in a Sorted Matrix
- LeetCode[378] Kth Smallest Element in a Sorted Matrix
- LeetCode:378 Kth Smallest Element in a Sorted Matrix
- leetCode No.378 Kth Smallest Element in a Sorted Matrix
- leetcode(378):Kth Smallest Element in a Sorted Matrix
- [Leetcode] 378 Kth Smallest Element in a Sorted Matrix
- Leetcode 378 Kth Smallest Element in a Sorted Matrix
- 378. Kth Smallest Element in a Sorted Matrix-binary search/heap
- 【Leetcode】Kth Smallest Element in a Sorted Matrix
- LeetCode—378. Kth Smallest Element in a Sorted Matrix
- Leetcode 378. Kth Smallest Element in a Sorted Matrix
- [leetcode] 378. Kth Smallest Element in a Sorted Matrix
- LeetCode 378. Kth Smallest Element in a Sorted Matrix
- 【leetcode】378. Kth Smallest Element in a Sorted Matrix
- leetcode之 Kth Smallest Element in a Sorted Matrix
- LeetCode:Kth Smallest Element in a Sorted Matrix
- leetcode---Kth Smallest Element in a Sorted Matrix
- 【腾讯TMQ】远程移动测试平台对比分析
- 线程间协作的两种方式:wait、notify、notifyAll和Condition
- 跟进View的常见周期回调以及View.post和Activity.runOnUiThread
- R语言去重复数据
- zxing扫描二维码和识别图片二维码及其优化策略
- leetcode :Binary Search:Kth Smallest Element in a Sorted Matrix(378)
- Python爬虫利器二之Beautiful Soup的用法
- Epplus组件导出Excel数据透视表
- laravel框架hasone与belongsto的with用法
- YCSB-HBase介绍与使用
- h264 图像、帧、片、NALU
- Redis百亿级Key存储方案
- genymotion启动报错:The virtual device got no IP address.
- Android studiio 编译时候 报错C:\Program Files\Java\jdk1.7.0_71\bin\java.exe'' finished with non-zero exit