diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/1944. Number of Visible People in a Queue.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/1944. Number of Visible People in a Queue.py" new file mode 100644 index 00000000..1081ba01 --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/1944. Number of Visible People in a Queue.py" @@ -0,0 +1,19 @@ +class Solution: + def canSeePersonsCount(self, heights: list[int]) -> list[int]: + n = len(heights) + answer = [0] * n + stack = [] + + for i in range(n - 1, -1, -1): + height = heights[i] + + while stack and stack[-1] < height: + stack.pop() + answer[i] += 1 + + if stack: + answer[i] += 1 + + stack.append(height) + + return answer