1337. 方阵中战斗力最弱的 K 行








class Solution(object):
    def kWeakestRows(self, mat, k):
        """
        :type mat: List[List[int]]
        :type k: int
        :rtype: List[int]
        """
        power = [sum(line) for line in mat]
        return sorted(list(range(len(mat))), key=lambda i: (power[i], i), reverse=False)[:k]

if __name__ == '__main__':
    solution = Solution()
    print(
        solution.kWeakestRows(mat=[[1, 1, 0, 0, 0], [1, 1, 1, 1, 0], [1, 0, 0, 0, 0], [1, 1, 0, 0, 0], [1, 1, 1, 1, 1]],
                              k=3))
原文地址:https://www.cnblogs.com/panweiwei/p/13065318.html