Problem :

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


My Solution :

class Solution:
    def dailyTemperatures(selfT):
        ans = [0]*len(T)
        INF = float('INF')
        min_idx_t = [INF]*102
        for i in range(len(T)-1, -1, -1):
            t = T[i]
            min_idx_t[t] = i
            min_idx = min(min_idx_t[t+1:])
            if min_idx is not INF:
                ans[i] = min_idx-i
        return ans


My Solution2 :

class Solution:
    def dailyTemperatures(selfT):
        ans = [0]*len(T)
        stack = []
        for i, t in enumerate(T):
            while stack and T[stack[-1]] < t:
                idx = stack.pop()
                ans[idx] = i - idx
            stack.append(i)
        return ans