File tree Expand file tree Collapse file tree 1 file changed +9
-9
lines changed
src/main/java/com/fishercoder/solutions Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Original file line number Diff line number Diff line change 66public class _1762 {
77 public static class Solution1 {
88 public int [] findBuildings (int [] heights ) {
9+ List <Integer > list = new ArrayList ();
910 int len = heights .length ;
10- int tallestBuildingOnTheRight = heights [len - 1 ];
11- List <Integer > list = new ArrayList <>();
11+ int higher = heights [len - 1 ];
1212 list .add (len - 1 );
1313 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 ) ;
1717 }
1818 }
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 );
2222 }
23- return num ;
23+ return res ;
2424 }
2525 }
2626}
You can’t perform that action at this time.
0 commit comments