Skip to content

Commit bbc49a3

Browse files
authored
Create 1762-buildings-with-an-ocean-view.js
1 parent df308a8 commit bbc49a3

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

1762-buildings-with-an-ocean-view.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @param {number[]} heights
3+
* @return {number[]}
4+
*/
5+
const findBuildings = function(heights) {
6+
const n = heights.length, suffix = Array(n).fill(0)
7+
let max = 0
8+
const res = [n - 1]
9+
for(let i = n - 2; i >= 0; i--) {
10+
max = Math.max(max, heights[i + 1])
11+
suffix[i] = max
12+
if(max < heights[i]) res.push(i)
13+
}
14+
res.reverse()
15+
return res
16+
};

0 commit comments

Comments
 (0)