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