Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def dailyTemperatures(self, temperatures: List[int]) -> List[int]:
- res = [0 for i in range(len(temperatures))]
- stack = [] # entries in the form (temp, index)
- i = 0
- current_temperature = None
- while i < len(temperatures):
- while stack and temperatures[i] > stack[-1][0]:
- temp, old_temp_index = stack.pop()
- res[old_temp_index] = i - old_temp_index
- stack.append((temperatures[i], i))
- i += 1
- return res
Advertisement
Add Comment
Please, Sign In to add comment