Skip to content

Commit 34e9f5a

Browse files
committed
Runtime: 143 ms (Top 19.44%) | Memory: 114.3 MB (Top 55.56%)
1 parent 911c379 commit 34e9f5a

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Runtime: 143 ms (Top 19.44%) | Memory: 114.3 MB (Top 55.56%)
12
class Solution {
23
public int maxBuilding(int n, int[][] restrictions) {
34
List<int[]> list=new ArrayList<>();
@@ -6,35 +7,35 @@ public int maxBuilding(int n, int[][] restrictions) {
67
list.add(restriction);
78
}
89
Collections.sort(list,new IDSorter());
9-
10+
1011
if(list.get(list.size()-1)[0]!=n){
1112
list.add(new int[]{n,n-1});
1213
}
13-
14+
1415
for(int i=1;i<list.size();i++){
1516
list.get(i)[1]=Math.min(list.get(i)[1],list.get(i-1)[1] + list.get(i)[0]-list.get(i-1)[0]);
1617
}
17-
18+
1819
for(int i=list.size()-2;i>=0;i--){
1920
list.get(i)[1]=Math.min(list.get(i)[1],list.get(i+1)[1] + list.get(i+1)[0] - list.get(i)[0]);
20-
}
21-
21+
}
22+
2223
int result=0;
2324
for(int i=1;i<list.size();i++){
24-
int h1=list.get(i-1)[1]; // heigth of previous restriction
25-
int h2=list.get(i)[1]; // height of current restriction
25+
int h1=list.get(i-1)[1]; // heigth of previous restriction
26+
int h2=list.get(i)[1]; // height of current restriction
2627
int x=list.get(i-1)[0]; // id of previous restriction
27-
int y=list.get(i)[0]; // id of current restriction
28-
28+
int y=list.get(i)[0]; // id of current restriction
29+
2930
result=Math.max(result,Math.max(h1,h2) + (y-x-Math.abs(h1-h2))/2);
30-
}
31+
}
3132
return result;
3233
}
33-
34+
3435
public class IDSorter implements Comparator<int[]>{
3536
@Override
3637
public int compare(int[] myself,int[] other){
3738
return myself[0]-other[0];
38-
}
39+
}
3940
}
40-
}
41+
}

0 commit comments

Comments
 (0)