Skip to content

Commit 838c623

Browse files
committed
Create Lt739.py
1 parent da4ce6b commit 838c623

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

LeetCode/Lt739.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from typing import List
2+
3+
class Solution:
4+
def dailyTemperatures(self, temperatures: List[int]) -> List[int]:
5+
"""No stack solution runs very slow"""
6+
# difference=[0] * len(temperatures) #emty list that will contain number of days it will take to get warmer
7+
8+
# #base
9+
# if len(temperatures) <=1:
10+
# difference[0] = 0
11+
# return difference
12+
13+
# for i in range(len(temperatures)):
14+
# sum=0
15+
# j= i + 1
16+
# while j < len(temperatures):
17+
# sum+=1
18+
19+
# if temperatures[i] < temperatures[j]:
20+
# difference[i] = sum
21+
# sum=0
22+
# break
23+
24+
# j+=1
25+
26+
27+
28+
# return difference
29+
30+
stack=[]
31+
difference=[0] * len(temperatures)
32+
33+
for i, currentTemp in enumerate(temperatures):
34+
while stack and temperatures[stack[-1]] < currentTemp:
35+
unsettledDay= stack.pop()
36+
difference[unsettledDay] = i - unsettledDay
37+
38+
stack.append(i)
39+
40+
return difference
41+
42+
array= [73,74,75,71,69,72,76,73]
43+
sol = Solution()
44+
print(sol.dailyTemperatures(array))

0 commit comments

Comments
 (0)