We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ead3083 commit c0a1ec4Copy full SHA for c0a1ec4
solution/0807.Max Increase to Keep City Skyline/Solution.cpp
@@ -0,0 +1,29 @@
1
+class Solution {
2
+public:
3
+ int maxIncreaseKeepingSkyline(vector<vector<int>>& grid)
4
+ {
5
+
6
+ vector<int> h(grid.size(), -1), w(grid[0]) ;
7
8
+ for (int i = 0; i < grid.size(); ++i)
9
+ for (int j = 0; j < grid[i].size(); ++j)
10
11
+ if (grid[i][j] > h[i])
12
+ h[i] = grid[i][j] ;
13
+ if (grid[i][j] > w[j])
14
+ w[j] = grid[i][j] ;
15
+ }
16
+ int sum = 0 ;
17
18
19
+ for (int j = 0; j < grid.size(); ++j)
20
21
+ int m = h[i] < w[j]? h[i]: w[j] ;
22
+ if (grid[i][j] < m)
23
+ sum += m - grid[i][j] ;
24
25
26
27
+ return sum ;
28
29
+};
0 commit comments