【Leetcode】807-1376

思路

不影响行和列的最大值,其实就是增大为行最大值和列最大值中的较小值。
利用zip函数求解列的最大值

class Solution:
    def maxIncreaseKeepingSkyline(self, grid: List[List[int]]) -> int:
        row_max = [max(row) for row in grid]
        column_max = [max(column) for column in zip(*grid)]
        return sum(min(row_max[i], column_max[j])-x for i,row in enumerate(grid) for j,x in enumerate(row))
posted @ 2024-07-14 16:47  TICSMC  阅读(7)  评论(0)    收藏  举报