807. 保持城市天际线

保持城市天际线

解法一: 贪心

go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
func maxIncreaseKeepingSkyline(grid [][]int) int {
m, n := len(grid), len(grid[0])
rArr := make([]int, n)
cArr := make([]int, m)
for i := 0; i < m; i++ {
for j := 0; j < n; j++ {
rArr[i] = max(rArr[i], grid[i][j])
cArr[j] = max(cArr[j], grid[i][j])
}
}
ans := 0
for i := 0; i < m; i++ {
for j := 0; j < n; j++ {
ans += max(grid[i][j], min(rArr[i], cArr[j])) - grid[i][j]
}
}
return ans
}
作者

wuhunyu

发布于

2024-07-14

更新于

2025-01-15

许可协议