This is the similar problem with: https://www.cnblogs.com/feiflytech/p/16169025.html

class Solution {
    public int[] dailyTemperatures(int[] t) {
        int[] res = new int[t.length];
        Stack<Integer> stk = new Stack<>();
        for(int i=0;i<t.length;i++){
            while(!stk.isEmpty() && t[i]>t[stk.peek()]){
                int index = stk.pop();
                res[index]=i-index;
            }
            stk.push(i);
        }
        
        return res;
    }
}

 

posted on 2022-04-20 13:43  阳光明媚的菲越  阅读(16)  评论(0编辑  收藏  举报