小顶堆,将矩阵中的值入堆,依次取堆顶值

import heapq
#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 
# @param matrix int整型二维数组 
# @param k int整型 
# @return int整型
#
class Solution:
    def KthinMatrix(self , matrix: List[List[int]], k: int) -> int:
        # write code here
        data = []
        n = len(matrix)
        for i in range(n):
            for j in range(n):
                heapq.heappush(data, matrix[i][j])
        s = 0
        val = 0
        while s < k and data:
            val = heapq.heappop(data)
            s += 1
        return val