Skip to content

Commit a02b4ff

Browse files
authored
Create 1944. Number of Visible People in a Queue.py
1 parent 2c42732 commit a02b4ff

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution:
2+
def canSeePersonsCount(self, heights: list[int]) -> list[int]:
3+
n = len(heights)
4+
answer = [0] * n
5+
stack = []
6+
7+
for i in range(n - 1, -1, -1):
8+
height = heights[i]
9+
10+
while stack and stack[-1] < height:
11+
stack.pop()
12+
answer[i] += 1
13+
14+
if stack:
15+
answer[i] += 1
16+
17+
stack.append(height)
18+
19+
return answer

0 commit comments

Comments
 (0)