nathanwailes

LeetCode 739 - Daily Temperatures - 2022.12.27 solution

Dec 27th, 2022
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.55 KB | None | 0 0
  1. class Solution:
  2.     def dailyTemperatures(self, temperatures: List[int]) -> List[int]:
  3.         res = [0 for i in range(len(temperatures))]
  4.         stack = []  # entries in the form (temp, index)
  5.         i = 0
  6.  
  7.         current_temperature = None
  8.         while i < len(temperatures):
  9.             while stack and temperatures[i] > stack[-1][0]:
  10.                 temp, old_temp_index = stack.pop()
  11.                 res[old_temp_index] = i - old_temp_index
  12.             stack.append((temperatures[i], i))
  13.  
  14.             i += 1
  15.        
  16.         return res
Advertisement
Add Comment
Please, Sign In to add comment