Skip to content

Commit f09e746

Browse files
Sean PrashadSean Prashad
authored andcommitted
Add 739_Daily_Temperatures.java
1 parent 24c34fb commit f09e746

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Arrays/739_Daily_Temperatures.java

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

0 commit comments

Comments
 (0)