Skip to content

Commit 9d9e6f1

Browse files
committed
[LEET] 1234 Number of Visible People in a Queue (hard)
1 parent bec4e9b commit 9d9e6f1

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

허현빈/3주차/260113.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @param {number[]} heights
3+
* @return {number[]}
4+
*/
5+
var canSeePersonsCount = function(heights) {
6+
const stack = [[heights[heights.length-1], 0]]
7+
const ans = [0]
8+
for(let i = heights.length-2; i >= 0; i--){
9+
const hValue = heights[i]
10+
let count = 0;
11+
for(let j = stack.length-1; j >= 0 ; j--){
12+
const sValue = stack[j]
13+
if(sValue[0] > heights[i]){
14+
count++
15+
break;
16+
}else{
17+
count++
18+
stack.pop()
19+
}
20+
}
21+
stack.push([heights[i], count])
22+
ans.push(count)
23+
}
24+
ans.reverse()
25+
return ans
26+
};

0 commit comments

Comments
 (0)