题目链接leetcode807
class Solution {
public int maxIncreaseKeepingSkyline(int[][] grid) {
int ans = 0;
int n = grid.length;
int[] west = new int[n];
int[] north = new int[n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
north[i] = Math.max(north[i], grid[j][i]);
west[i] = Math.max(west[i], grid[i][j]);
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
ans += Math.min(west[i], north[j]) - grid[i][j];
}
}
return ans;
}
}