My Progress

[Leetcode] 739. Daily Temperatures 본문

Coding Problems

[Leetcode] 739. Daily Temperatures

ghwangbo 2025. 2. 13. 09:18
반응형

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.

 

 

A key point of this question was to make the stack in ascending order. Since we are finding the number of days for ith day to get a warmer temperature, it is easy to traverse the array in reverse order. Since we are only finding the closest day with a warmer temperature, we can simply pop a smaller value in our stack as we are traversing.

반응형

'Coding Problems' 카테고리의 다른 글

853. Car Fleet  (0) 2025.02.13