题目链接
方法1 n路插入排序
O(kn)
class Solution:
def kthSmallest(self, matrix: List[List[int]], k: int) -> int:
n=len(matrix)
while(k):
k-=1
minn=1e10
minind=0
for i in range(n):
if matrix[i] and matrix[i][0]<minn:
minn=matrix[i][0]
minind=i
matrix[minind].pop(0)
if k==0:
return minn