Max Increase to Keep City Skyline LeetCode solution in Java

1
class Solution {
2
public int maxIncreaseKeepingSkyline(int[][] grid) {
3
int n = grid.length;
4
int[] row = new int[n];
5
int[] col = new int[n];
6
int ans = 0;
7
for (int i = 0; i < n; i++) {
8
for (int j = 0; j < n; j++) {
9
row[i] = Math.max(row[i], grid[i][j]);
10
col[i] = Math.max(col[i], grid[j][i]);
11
}
12
}
13
for (int i = 0; i < n; i++) {
14
for (int j = 0; j < n; j++) {
15
ans += Math.min(row[i], col[j]) - grid[i][j];
16
}
17
}
18
return ans;
19
}
20
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0