1337. The K Weakest Rows in a Matrix

Обновлено: 2024-03-12
1 мин
[]

Содержание

LeetCode problem 1337

class Solution:
    def kWeakestRows(self, mat: List[List[int]], k: int) -> List[int]:
        m, n = len(mat), len(mat[0])
        res = [n - bisect_right(row[::-1], 0) for row in mat]
        idx = list(range(m))
        idx.sort(key=lambda i: res[i])
        return idx[:k]