代码:
class Solution {
public int[] dailyTemperatures(int[] temperatures) {
Deque<int[]> stack = new ArrayDeque<>();
stack.push(new int[]{-1,Integer.MAX_VALUE});
int n = temperatures.length;
int[] res = new int[n];
for(int i=n-1;i>=0;i--){
while(temperatures[i]>=stack.peek()[1]){
stack.pop();
}
res[i] = stack.peek()[0]-i;
if(res[i]<0)res[i]=0;
stack.push(new int[]{i,temperatures[i]});
}
return res;
}
}