0807.cpp (585B)
1 class Solution { 2 public: 3 int maxIncreaseKeepingSkyline(const vector<vector<int>> &grid) { 4 int row[51] = {0}, col[51] = {0}; 5 int n = grid.size(); 6 7 for (int i = 0; i < n; i++) { 8 for (int j = 0; j < n; j++) { 9 row[i] = max(row[i], grid[i][j]); 10 col[j] = max(col[j], grid[i][j]); 11 } 12 } 13 14 int res = 0; 15 for (int i = 0; i < n; i++) { 16 for (int j = 0; j < n; j++) { 17 res += min(row[i], col[j]) - grid[i][j]; 18 } 19 } 20 21 return res; 22 } 23 };