【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))

浙公网安备 33010602011771号