Skip to content

Commit 351a222

Browse files
Create Daily temperature - 739
1 parent b912c14 commit 351a222

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Daily temperature - 739

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

0 commit comments

Comments
 (0)