首页 > 其他 > 详细

经典每日温度升高问题

时间:2021-08-30 01:19:07      阅读:30      评论:0      收藏:0      [点我收藏+]
class Solution {
    public int[] dailyTemperatures(int[] temperatures) {
        Deque<Integer> sta = new LinkedList<>();
        int[] res = new int[temperatures.length];
        for(int i = 0 ; i < temperatures.length;i++){
            while(!sta.isEmpty() && temperatures[sta.peekLast()] < temperatures[i]){
                int index = sta.pollLast();
                res[index] = i-index; 
            }
            sta.addLast(i);
        }
        return res;
    }
}

这题就是用栈做每日弹出,就是传值的逻辑有点乱,栈存储的是数组索引,通过栈找到当日温度比较大于当日后,存储到目标数组中。

经典每日温度升高问题

原文:https://www.cnblogs.com/Dkfeng/p/15193878.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!