Skip to content

Commit 63a96bc

Browse files
iamAntimPalAntim-IWPIamShiwangi
committed
Update 739. Daily Temperatures.py
Co-Authored-By: Antim-IWP <203163676+Antim-IWP@users.noreply.github.com> Co-Authored-By: Shiwangi Srivastava <174641070+IamShiwangi@users.noreply.github.com>
1 parent a36e3c9 commit 63a96bc

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution:
2+
def dailyTemperatures(self, temperatures: List[int]) -> List[int]:
3+
stk = []
4+
n = len(temperatures)
5+
ans = [0] * n
6+
for i in range(n - 1, -1, -1):
7+
while stk and temperatures[stk[-1]] <= temperatures[i]:
8+
stk.pop()
9+
if stk:
10+
ans[i] = stk[-1] - i
11+
stk.append(i)
12+
return ans

0 commit comments

Comments
 (0)