Skip to content

Commit 2eb9d5e

Browse files
committed
feat: LC739
1 parent 560a82b commit 2eb9d5e

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

LC/LC739.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'''
2+
739. Daily Temperatures
3+
4+
Given an array of integers temperatures represents the daily temperatures, return an array answer such that answer[i] is the number of days you have to wait after the ith day to get a warmer temperature. If there is no future day for which this is possible, keep answer[i] == 0 instead.
5+
6+
Example 1:
7+
8+
Input: temperatures = [73,74,75,71,69,72,76,73]
9+
Output: [1,1,4,2,1,1,0,0]
10+
Example 2:
11+
12+
Input: temperatures = [30,40,50,60]
13+
Output: [1,1,1,0]
14+
Example 3:
15+
16+
Input: temperatures = [30,60,90]
17+
Output: [1,1,0]
18+
'''
19+
from typing import *
20+
class Solution:
21+
def dailyTemperatures(self, temperatures: List[int]) -> List[int]:
22+
results = [0] * len(temperatures)
23+
stack = []
24+
for i, temp in enumerate(temperatures):
25+
while stack and temperatures[stack[-1]] < temp:
26+
index = stack.pop()
27+
results[index] = i - index
28+
stack.append(i)
29+
return results
30+
31+
32+
temperatures = [73,74,75,71,69,72,76,73]
33+
s = Solution()
34+
print(s.dailyTemperatures(temperatures))
35+
36+

0 commit comments

Comments
 (0)