739. Daily Temperatures
- also record both index and items in the stack
class Solution(object):
def dailyTemperatures(self, temperatures):
stack = []
res = [0] * (len(temperatures))
for index, item in enumerate(temperatures):
while stack:
last_item, last_index = stack[-1]
if item <= last_item:
break
last_item, last_index = stack.pop()
res[last_index] = index - last_index
stack.append((item, index))
return res