博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
378. Kth Smallest Element in a Sorted Matrix
阅读量:4356 次
发布时间:2019-06-07

本文共 720 字,大约阅读时间需要 2 分钟。

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.

Example:

matrix = [

[ 1, 5, 9],
[10, 11, 13],
[12, 13, 15]],
k = 8,

return 13.

Note:

You may assume k is always valid, 1 ≤ k ≤ n2.

class Solution:    def kthSmallest(self, matrix, k):        """        :type matrix: List[List[int]]        :type k: int        :rtype: int        """        res = []        for i in range(matrix):            for j in range(matrix[0]):                res.append(matrix[i][j])        return sorted(res[k-1])

转载于:https://www.cnblogs.com/bernieloveslife/p/9806239.html

你可能感兴趣的文章
MaxComputer 使用客户端配置
查看>>
20190823 顺其自然
查看>>
阅读《余生有你,人间值得》有感
查看>>
每日英语
查看>>
[leetcode] Regular Expression Matching
查看>>
BZOJ1927: [Sdoi2010]星际竞速(最小费用最大流 最小路径覆盖)
查看>>
洛谷P1317 低洼地
查看>>
MVC Redirect 页面跳转不了
查看>>
李开复有哪些地方做的不好
查看>>
12.22
查看>>
新版本的molar mass(uva-1586)明明debug过了,各种测试还是WA真是气死我了
查看>>
gdb(ddd,kdevelop等)调试ZeroIce开发的应用程序,中断信号引起的问题
查看>>
牛股助推器(每股收益率)
查看>>
SpringCloud+feign 基于Springboot2.0 负载均衡
查看>>
【BZOJ5094】硬盘检测 概率
查看>>
mac上n次安装与卸载mysql
查看>>
Python之单元测试——HTMLTestRunner
查看>>
WebNotes(PHP、css、JavaScript等)
查看>>
C++:文件的输入和输出
查看>>
Http协议、Tomcat、servlet
查看>>