Skip to content

Commit 1a8ad2e

Browse files
committed
- Add: Number of Visible People in a Queue
1 parent eb3b57d commit 1a8ad2e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
fun canSeePersonsCount(heights: IntArray): IntArray {
3+
val size = heights.size
4+
val res = IntArray(size)
5+
val st = LinkedList<Int>()
6+
7+
for (i in size - 1 downTo 0) {
8+
val curPerson = heights[i]
9+
10+
while (st.isNotEmpty()) {
11+
val nextPerson = st.peek()
12+
13+
res[i]++
14+
if (nextPerson > curPerson) break
15+
else st.pop()
16+
}
17+
st.push(curPerson)
18+
}
19+
return res
20+
}
21+
}

0 commit comments

Comments
 (0)