본문 바로가기

Algorithm/파이썬 알고리즘 인터뷰 스터디

[스택, 큐] 22 일일 온도(Daily Temperatures) - 작성중

<LeetCode 문제>

https://leetcode.com/problems/daily-temperatures/

 

Daily Temperatures - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

매일의 화씨 온도 리스트 T를 입력받아서, 더 따뜻한 날씨를 위해서는 며칠을 더 기다려야 하는지를 출력하는 문제입니다.

<풀이>

class Solution:
    def dailyTemperatures(self, temperatures: List[int]) -> List[int]:
        ans=[0]*len(temperatures)
        stack=[] #stack 선언
        
        for i,cur in enumerate(temperatures):
            while stack and cur >temperatures[stack[-1]]:
                last = stack.pop()
                ans[last] = i-last
            stack.append(i)
            
        return ans

<학습내용>

1.

<학습이 필요한 내용>

1.