Gary Lai
  • Home
  • About
Sign in Subscribe

739. Daily Temperatures

Last updated on  Apr 2, 2025

739. Daily Temperatures

class Solution:
    def dailyTemperatures(self, temperatures: List[int]) -> List[int]:
        
        n = len(temperatures) 
        res = [0] * n
        s = []

        for i in range(n-1, -1, -1):
            while s and temperatures[s[-1]] <= temperatures[i]:
                s.pop()
            res[i] = 0 if not s else s[-1] - i
            s.append(i)
        
        return res
Previous 496. Next Greater Element I
Next 901. Online Stock Span
Gary Lai © 2025
  • Sign up
Powered by Ghost