Skip to content

Commit e25318a

Browse files
authored
Create Solution.java
1 parent fe2f068 commit e25318a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public int[] dailyTemperatures(int[] T) {
3+
int n = T.length;
4+
int[] res = new int[n];
5+
ArrayDeque<Integer> stack = new ArrayDeque<>();
6+
for (int i = 0; i < n; ++i) {
7+
while (!stack.isEmpty() && T[stack.peek()] < T[i]) {
8+
res[stack.peek()] = i - stack.peek();
9+
stack.pop();
10+
}
11+
stack.push(i);
12+
}
13+
return res;
14+
}
15+
}

0 commit comments

Comments
 (0)