-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path807.cpp
More file actions
23 lines (23 loc) · 701 Bytes
/
Copy path807.cpp
File metadata and controls
23 lines (23 loc) · 701 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Solution {
public:
int maxIncreaseKeepingSkyline(vector<vector<int>> &grid) {
int m = grid.size(), n = m == 0 ? 0 : grid[0].size();
if (m == 0)
return 0;
vector<int> row(m, 0), col(n, 0);
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j) {
row[i] = max(row[i], grid[i][j]);
col[j] = max(col[j], grid[i][j]);
}
}
int total = 0;
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j) {
int highest = min(row[i], col[j]);
total += max(0, highest - grid[i][j]);
}
}
return total;
}
};