Leetcode:378. Kth Smallest Element in a Sorted Matrix
来源:互联网 发布:linux中链接目的 编辑:程序博客网 时间:2024/06/12 20:30
算法:使用nth_number()函数
class Solution {public: int kthSmallest(vector<vector<int>>& matrix, int k) { int row=matrix.size(); int col=matrix[0].size(); int* number = new int[row*col]; for(int i=0; i<row; i++){ for(int j=0; j<col; j++){ number[i*col+j]=matrix[i][j]; } } nth_element(number, number+k-1, number+(row*col)); return number[k-1]; }};
nth_number()的使用参考:
http://blog.csdn.net/guofengzai/article/details/2574225
阅读全文
0 0
- 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】378. Kth Smallest Element in a Sorted Matrix
- Leetcode-378. Kth Smallest Element in a Sorted Matrix
- 378. [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]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
- SPOJ
- centos 6.9二进制安装mariadb 5.5.57
- 如何在多文本中提取指定数据,并按时间命名文件名
- 深度理解并设置 placeholder 属性,定制自己的 textField
- sdut 2088 数据结构实验之栈与队列十一:refresh的停车场
- Leetcode:378. Kth Smallest Element in a Sorted Matrix
- python学习:更多字符串的内容
- Windows环境下配置python spark(windows7+python+spark)
- 日记(3)
- input tensor values 困惑
- 持续更新 | PMCAFF问答专场活动分享笔记大合集
- 浅谈机器人产品落地全过程
- C++笔记——类、对象和封装
- javascript执行上下文、作用域与闭包(第五篇)---一个例子的理解