--- title: 807. Max Increase to Keep City Skyline tags: Greedy description: share source code. --- # 807. Max Increase to Keep City Skyline ```java= class Solution { public int maxIncreaseKeepingSkyline(int[][] grid) { int n = grid.length; int m = grid[0].length; int row [] = new int [n]; int col [] = new int [m]; int res = 0; for(int i = 0; i < n; i++){ int max = 0; for(int j = 0; j < m; j++){ row[j] = Math.max(grid[i][j], row[j]); max = Math.max(max, grid[i][j]); res -= grid[i][j]; } col [i] = max; } for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){ if(grid[i][j] != row [j] && grid[i][j] != col [i]){ res += Math.min(row [j], col [i]); }else{ res += grid[i][j]; } } } return res ; } } ```