Skip to content

Commit 8155611

Browse files
committed
807
1 parent 659c17f commit 8155611

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

807.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
class Solution {
2+
public:
3+
int maxIncreaseKeepingSkyline(vector<vector<int>>& grid) {
4+
int x=grid.size();
5+
int y=grid[0].size();
6+
int A[x][y];
7+
for(int i=0;i<x;i++){
8+
for(int j=0;j<y;j++){
9+
A[i][j]=grid[i][j];
10+
}
11+
}
12+
int B[y];
13+
for(int j=0;j<y;j++){
14+
int max1=INT_MIN;
15+
for(int i=0;i<x;i++){
16+
if(A[i][j] > max1){
17+
max1=A[i][j];
18+
}
19+
B[j]=max1;
20+
}
21+
}
22+
int C[x];
23+
for(int j=0;j<x;j++){
24+
int max2=INT_MIN;
25+
for(int i=0;i<y;i++){
26+
if(A[j][i] > max2){
27+
max2=A[j][i];
28+
}
29+
C[j]=max2;
30+
}
31+
}
32+
for(int i=0;i<x;i++){
33+
for(int j=0;j<y;j++){
34+
A[i][j]=min(B[j],C[i]);
35+
}
36+
}
37+
long long int sum=0;
38+
for(int i=0;i<x;i++){
39+
for(int j=0;j<y;j++){
40+
sum=sum+( A[i][j] - grid[i][j] );
41+
}
42+
}
43+
return sum;
44+
}
45+
};

0 commit comments

Comments
 (0)