378. Kth Smallest Element in a Sorted Matrix

use heap/priority q , pop k times, push k times
import heapq
class Solution(object):
    def kthSmallest(self, matrix, k):
        """
        :type matrix: List[List[int]]
        :type k: int
        :rtype: int
        """
        result,heap=None,[]
        heapq.heappush(heap,(matrix[0][0],0,0))
        while k>0:
            result,i,j=heapq.heappop(heap)
            if i==0 and j+1

你可能感兴趣的:(378. Kth Smallest Element in a Sorted Matrix)