def dailyTemperatures(temperatures):
ans = [0] * len(temperatures) #temperatures리스트를 다 순회했을 때 0을 반환하기 위함
#out of index를 방지하기 위함
stack = []
for cur_day, cur_temp in enumerate(temperatures):
while stack and stack[-1][1] < cur_temp:
prev_day, _ = stack.pop() #튜플을 꺼낼 때 한쪽값은 무시하고, 다른 한쪽 값만 뽑기
ans[prev_day] = cur_day - prev_day
stack.append((cur_day, cur_temp ))
return ans
print(dailyTemperatures([73,74,75,71,69,72,76,73]))
#통상적인 for문 + while문
#for문을 1번 반복 → while n번 반복
#for문을 2번 반복 → while 2n번 반복
#for문을 3번 반복 → while 3n번 반복
#for문을 n번 반복 → while n^2번 반복 O(n^2)
#for문을 n번 반복 할때 while을 n^2반복
#위 문제의 경우
#for문을 n번 반복해야 while문을 n번 반복 → O(n)