Skip to content

Commit a1b637a

Browse files
update 1762
1 parent a26eb08 commit a1b637a

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

Diff for: src/main/java/com/fishercoder/solutions/_1762.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@
66
public 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
}

0 commit comments

Comments
 (0)