From a02b4ff5324f368bbed1980b5c3b2ab2f3eaae6b Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Sun, 18 Oct 2026 22:45:20 +0900 Subject: [PATCH] Create 1944. Number of Visible People in a Queue.py --- ...4. Number of Visible People in a Queue.py" | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 "leetcode3/\354\265\234\354\233\220\354\244\200/1944. Number of Visible People in a Queue.py" 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