File tree 1 file changed +9
-9
lines changed
src/main/java/com/fishercoder/solutions
1 file changed +9
-9
lines changed Original file line number Diff line number Diff line change 6
6
public class _1762 {
7
7
public static class Solution1 {
8
8
public int [] findBuildings (int [] heights ) {
9
+ List <Integer > list = new ArrayList ();
9
10
int len = heights .length ;
10
- int tallestBuildingOnTheRight = heights [len - 1 ];
11
- List <Integer > list = new ArrayList <>();
11
+ int higher = heights [len - 1 ];
12
12
list .add (len - 1 );
13
13
for (int i = len - 2 ; i >= 0 ; i --) {
14
- if (heights [i ] > tallestBuildingOnTheRight ) {
15
- list . add ( 0 , i ) ;
16
- tallestBuildingOnTheRight = heights [ i ] ;
14
+ if (heights [i ] > higher ) {
15
+ higher = heights [ i ] ;
16
+ list . add ( i ) ;
17
17
}
18
18
}
19
- int [] num = new int [list .size ()];
20
- for (int i = 0 ; i < list . size () ; i ++) {
21
- num [ i ] = list .get (i );
19
+ int [] res = new int [list .size ()];
20
+ for (int i = list . size () - 1 , j = 0 ; i >= 0 ; i --, j ++) {
21
+ res [ j ] = list .get (i );
22
22
}
23
- return num ;
23
+ return res ;
24
24
}
25
25
}
26
26
}
You can’t perform that action at this time.
0 commit comments