LeetCode 739. 每日温度

OJ链接: 739. 每日温度

示例代码:

复制代码
class Solution {
    public int[] dailyTemperatures(int[] temperatures) {
            int length =  temperatures.length;
    //数组存储下标记录
            int[] ans = new int[length];
            Stack<Integer> stack = new Stack<>();

            for(int i =0 ; i<length ;i++){
    //遍历每个温度
                int temp = temperatures[i]; 
           //当栈不为空 且 当前温度大于栈顶温度
                while( !stack.empty() && temp > temperatures[stack.peek()]){
    //出栈 ,并记录下标
                   int perv = stack.pop();
                    ans[perv] = i - perv;
                }
                stack.push(i);
            }
            return ans;
    }
}
相关推荐
吴声子夜歌3 小时前
Java扩展——OkHttp
java·开发语言·okhttp
卓怡学长3 小时前
w210基于springboot反诈平台设计与实现
java·spring boot·spring·intellij-idea
萧瑟余晖3 小时前
Java深入解析篇六十一之编译器API(javax.tools)详解
java·开发语言
HugoStudio_SWAN4 小时前
洛谷 P10719 \[GESP202406 五级] 黑白格——暴力美学与图像处理的最小外接矩形
c++·图像处理·人工智能·学习·程序人生·算法·目标跟踪
那年窗外下的雪.4 小时前
AIDC 学习日志|第 20 天|多归属业务验收与哈希不均定位
学习·算法·哈希算法
码云数智-园园4 小时前
C++ STL 容器怎么选?vector、list、map、unordered_map 优缺点对比
java·开发语言
YSL0701244 小时前
时间复杂度和空间复杂度
数据结构
en.en..4 小时前
竖线 |:管道、按位或、掩码组合
java·开发语言
洋不写bug4 小时前
链表面试笔试经典题目详细解析,题目多解法,复杂度分析
数据结构·链表·面试
程序猿乐锅5 小时前
【计算机组成原理 | 第六章】中央处理器 CPU
java·开发语言