解题思路
单调栈的经典题型。
我们需要找到temperatures[i]的右边最近的小于temperatures[i]的值,所以就想到了单调栈。
相关代码
class Solution {
    public int[] dailyTemperatures(int[] temperatures) {
        Stack<Integer> stack = new Stack<>();
        int res[] = new int[temperatures.length];
        int n = temperatures.length;
        for(int i=n-1;i>=0;i--){
            //进行筛选
            while(stack.isEmpty()==false&&temperatures[i]>=temperatures[stack.peek()]) stack.pop();
            if(stack.isEmpty()==true) res[i]=0;
            else res[i]=Math.abs(stack.peek()-i);
            stack.push(i);
        }
        return res;
    }
}