leetcode379

用到了栈

class Solution {
    public int[] dailyTemperatures(int[] T) {
        if(T==null||T.length==0) return T;
        int[] res = new int[T.length];
        Stack<Integer> stack = new Stack<>();
        res[res.length-1] = 0;
        for(int i = 0;i<res.length-1;i++){
            if(T[i+1]>T[i]){
                res[i]=1;
                if(!stack.isEmpty()){
                    while(!stack.isEmpty()&&T[stack.peek()]<T[i+1]){
                        int popS =stack.pop();
                        res[popS] = i+1-popS;
                    }
                }
            }else{
                stack.push(i);
            }
        }
        return res;

    }
}
原文地址:https://www.cnblogs.com/ljf-0/p/14172770.html