Skip to content

Commit f9190b9

Browse files
Create 739. Daily Temperatures
leetcode daily challenge 739. Daily Temperatures using stack or monostack
1 parent 6e23b02 commit f9190b9

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

739. Daily Temperatures

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution(object):
2+
def dailyTemperatures(self, temperatures):
3+
ans=[0]
4+
l=len(temperatures)
5+
list1=[l-1]
6+
top=0
7+
for i in range(l-2,-1,-1):
8+
if temperatures[i]<temperatures[list1[-1]]:
9+
ans.append(list1[-1]-i)
10+
list1.append(i)
11+
top+=1
12+
else:
13+
while top>=0 and temperatures[list1[top]]<=temperatures[i]:
14+
top-=1
15+
list1.pop()
16+
if top<0:
17+
ans.append(0)
18+
else:
19+
ans.append(list1[top]-i)
20+
21+
list1.append(i)
22+
top+=1
23+
return ans[::-1]

0 commit comments

Comments
 (0)