[Leetcode]739. Daily Temperatures(x)
2024. 8. 2. 08:08ㆍAlgorithm
1. problem :
https://leetcode.com/problems/daily-temperatures/
2. solution 1 :
class Solution:
def dailyTemperatures(self, temperatures: List[int]) -> List[int]:
ans = [0] * len(temperatures)
stack = []
for i,temp in enumerate(temperatures):
while stack and temperatures[stack[-1]] < temp:
idx = stack.pop()
ans[idx] = i - idx
stack.append(i)
return ans'Algorithm' 카테고리의 다른 글
| [Leetcode]84. Largest Rectangle in Histogram(x) (0) | 2024.08.02 |
|---|---|
| [Leetcode]853. Car Fleet(x) (0) | 2024.08.02 |
| [Leetcode]22. Generate Parentheses(x) (0) | 2024.08.02 |
| [Leetcode]150. Evaluate Reverse Polish Notation (0) | 2024.08.01 |
| [Leetcode]155. Min Stack (0) | 2024.08.01 |