- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1762.java
26 lines (24 loc) · 781 Bytes
/
_1762.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
packagecom.fishercoder.solutions.secondthousand;
importjava.util.ArrayList;
importjava.util.List;
publicclass_1762 {
publicstaticclassSolution1 {
publicint[] findBuildings(int[] heights) {
List<Integer> list = newArrayList();
intlen = heights.length;
inthigher = heights[len - 1];
list.add(len - 1);
for (inti = len - 2; i >= 0; i--) {
if (heights[i] > higher) {
higher = heights[i];
list.add(i);
}
}
int[] res = newint[list.size()];
for (inti = list.size() - 1, j = 0; i >= 0; i--, j++) {
res[j] = list.get(i);
}
returnres;
}
}
}