Write a function Given a list of daily temperatures T, return a list such that, for each day in the input, tells you how many days you would have to wait until a warmer temperature. If there is no future day for which this is possible, put 0 instead.


Topic: Write a function Given a list of daily temperatures T, return a list such that, for each day in the input, tells you how many days you would have to wait until a warmer temperature. If there is no future day for which this is possible, put 0 instead.

Solution

def dailyTemperatures(T):
    stack = []
    res = [0 for _ in range(len(T))]
    for i, t1 in enumerate(T):
        while stack and t1 > stack[-1][1]:
            j, t2 = stack.pop()
            res[j] = i - j
        stack.append((i, t1))
    return res
	
	



List all Python Programs