739. Daily temperature

From the daily temperature list, create a new list with the input of how long you have to wait for the temperature to rise beyond the number of days that day. If it does not rise after that, replace it with 0 at that position.

Temperatures = [73, 74, 75, 71, 69, 72, 76, 73]

Output: [1, 1, 4, 2, 1, 1, 0, 0].

Note: The length range of the temperature list is [1, 30000]. Each temperature is an integer in the [30, 100] range of degrees Fahrenheit.

class Solution:
    def dailyTemperatures(self, T: List[int]) -> List[int]:
        stack = []  # stack
        res = [0] * len(T)
        for i, t in enumerate(T):
            while stack and T[stack[- 1]] < t:
                c = stack.pop()
                res[c] = i - c
            stack.append(i)
        return res
""" """ """ """ """ """ """ """ """ """ """ """ """ """ """
Copy the code