Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c0a1ec4

Browse files
create 0807 folder & cpp solution
1 parent ead3083 commit c0a1ec4

File tree

1 file changed

+29
-0
lines changed
  • solution/0807.Max Increase to Keep City Skyline

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
for (int i = 0; i < grid.size(); ++i)
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

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /