Skip to content

Commit 244b485

Browse files
authored
Update 1944-number-of-visible-people-in-a-queue.js
1 parent 2db0eac commit 244b485

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

1944-number-of-visible-people-in-a-queue.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
/**
2+
* @param {number[]} heights
3+
* @return {number[]}
4+
*/
5+
const canSeePersonsCount = function(heights) {
6+
const res = []
7+
if(heights.length === 0) return res
8+
9+
const n = heights.length
10+
const stk = []
11+
for(let i = n - 1; i >= 0; i--) {
12+
let del = 0
13+
while(stk.length && heights[i] > heights[stk[stk.length - 1]]) {
14+
stk.pop()
15+
del++
16+
}
17+
res.push(del + (stk.length ? 1 : 0))
18+
stk.push(i)
19+
}
20+
21+
return res.reverse()
22+
};
23+
24+
// another
25+
26+
127
/**
228
* @param {number[]} heights
329
* @return {number[]}

0 commit comments

Comments
 (0)