파이썬 알고리즘 인터뷰 문제 22번(리트코드 739번) Daily Temperatures
https://leetcode.com/problems/daily-temperatures/
class Solution:
def dailyTemperatures(self, temperatures: List[int]) -> List[int]:
stack = []
result = [0] * len(temperatures)
for index, temperature in enumerate(temperatures):
while stack and temperatures[stack[-1]] < temperatures[index]:
day = stack.pop()
result[day] = index - day
stack.append(index)
return result
stack에 온도가 아닌 온도의 index를 저장할 생각을 떠올리지 못했다.index를 저장하는 것이 자연스럽고 당연하다. 지금 생각해보면 당연한데 그때는 왜 떠올리지 못했을까.