Skip to content

Commit 2b6facd

Browse files
Time: 82 ms (17.35%), Space: 60.4 MB (56.54%) - LeetHub
1 parent e128754 commit 2b6facd

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
public int[] dailyTemperatures(int[] temperatures) {
3+
4+
Stack<Integer> help = new Stack<>();
5+
int n = temperatures.length;
6+
int[] result= new int[n];
7+
for(int i = n - 1;i>=0;i--){
8+
while(!help.isEmpty()&&temperatures[i]>=temperatures[help.peek()]){
9+
help.pop();
10+
}
11+
if(!help.isEmpty()){
12+
result[i]=help.peek()-i;
13+
}
14+
help.push(i);
15+
16+
}
17+
return result;
18+
19+
}
20+
}

0 commit comments

Comments
 (0)