My python solution by flattening the matrix (124 ms)

  • 0
     def kthSmallest_124(self, matrix, k):
            :type matrix: List[List[int]]
            :type k: int
            :rtype: int
            flatten = lambda x: [y for l in x for y in flatten(l)] if type(x) is list else [x]
            matrix = flatten(matrix)
            return matrix[k-1]

    I just used the default sorting method. Could be better.

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.