엔지니어 게시판
LeetCode 솔루션 분류

[12/18] 739. Daily Temperatures

컨텐츠 정보

본문

Given an array of integers temperatures represents the daily temperatures, return an array answer such that answer[i] is the number of days you have to wait after the ith day to get a warmer temperature. If there is no future day for which this is possible, keep answer[i] == 0 instead.

 

Example 1:

Input: temperatures = [73,74,75,71,69,72,76,73]
Output: [1,1,4,2,1,1,0,0]

Example 2:

Input: temperatures = [30,40,50,60]
Output: [1,1,1,0]

Example 3:

Input: temperatures = [30,60,90]
Output: [1,1,0]

 

Constraints:

  • <li style="border: 0px solid; box-sizing: border-box; --tw-border-spacing-x:0; --tw-border-spacing-y:0; --tw-translate-x:0; --tw-translate-y:0; --tw-rotate:0; --tw-skew-x:0; --tw-skew-y:0; --tw-scale-x:1; --tw-scale-y:1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ; --tw-scroll-snap-strictness:proximity; --tw-ordinal: ; --tw-slashed-zero: ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ; --tw-ring-inset: ; --tw-ring-offset-width:0px; --tw-ring-offset-color:#fff; --tw-ring-color:rgba(59,130,246,0.5); --tw-ring-offset-shadow:0 0 #0000; --tw-rin

관련자료

댓글 1

학부유학생님의 댓글

  • 익명
  • 작성일
import heapq
class Solution:
    def dailyTemperatures(self, temperatures: List[int]) -> List[int]:
        minheap = []
        heapq.heapify(minheap)

        res = [0]*len(temperatures)

        for idx, num in enumerate(temperatures):
            heapq.heappush(minheap, (num, idx))

            while minheap and minheap[0][0] < num:
                temp, index = heapq.heappop(minheap)

                res[index] = idx-index


        return res
전체 194 / 2 페이지
번호
제목
이름

최근글


인기글


새댓글


Stats


  • 현재 접속자 751 명
  • 오늘 방문자 7,002 명
  • 어제 방문자 6,975 명
  • 최대 방문자 14,831 명
  • 전체 회원수 1,537 명
알림 0