https://leetcode.com/problems/daily-temperatures/description/
1
2
3
4
5
6
7
8
9
10
11
|
class Solution:
def dailyTemperatures(self, temperatures: List[int]) -> List[int]:
answer = [0] * len(temperatures)
stack = []
for i, cur in enumerate(temperatures):
while stack and cur > temperatures[stack[-1]]:
last = stack.pop()
answer [last] = i -last
stack.append(i)
return answer
|
cs |
반응형
'python-algorithm' 카테고리의 다른 글
백준 27541 末尾の文字 (Last Letter) (0) | 2023.02.24 |
---|---|
leetcode 232. Implement Queue using Stacks (0) | 2023.02.23 |
leetcode 316. Remove Duplicate Letters (1) | 2023.02.23 |
leetcode 20. Valid Parentheses (0) | 2023.02.23 |
백준 9773 ID Key (0) | 2023.02.21 |
댓글