当前位置:网站首页>leetcode 739. Daily Temperatures 每日温度(中等)
leetcode 739. Daily Temperatures 每日温度(中等)
2022-08-10 13:26:00 【InfoQ】
一、题目大意
- 1 <= temperatures.length <= 105
- 30 <= temperatures[i] <= 100
二、解题思路
- 什么是单调栈?单调栈通过维持栈内值的单调递增(递减)性,在整体O(n)的时间内处理需要大小比较的问题。
三、解题方法
3.1 Java实现
public class Solution {
public int[] dailyTemperatures(int[] temperatures) {
int[] ans = new int[temperatures.length];
Stack<Integer> desStack = new Stack<>();
for (int i = 0; i < temperatures.length; i++) {
while (!desStack.isEmpty()) {
int preIndex = desStack.peek();
if (temperatures[i] <= temperatures[preIndex]) {
break;
}
desStack.pop();
ans[preIndex] = i - preIndex;
}
desStack.push(i);
}
return ans;
}
}
四、总结小记
- 2022/8/10 下雨、下雪本是很好玩的事,大了之后也不尽然,出行、生产、工作都会受到影响
边栏推荐
- 接口自动化测试基础篇
- 汉字检测和关键词检测
- C# error The 'xmins' attribute is not supported in this context
- C#中导入其它自定义的命名空间
- Error: Rule can only have one resource source (provided resource and test + include + exclude)
- 代码随想录笔记_动态规划_70爬楼梯
- 第三方软件测评有什么作用?权威软件检测机构推荐
- 递归递推之计算组合数
- C#报错 The ‘xmins‘ attribute is not supported in this context
- Short read or OOM loading DB. Unrecoverable error, aborting now
猜你喜欢
mSystems | Zhongnong Wang Jie Group Reveals the Mechanisms Affecting Soil "Plastic Interstitial" Microbial Communities
鸿蒙开发从hello world开始
第三方软件测评有什么作用?权威软件检测机构推荐
友邦人寿可观测体系设计与落地
Ethernet channel Ethernet channel
“Oracle 封禁了我的账户”
什么?你还不会JVM调优?
【量化交易行情不够快?】一文搞定通过Win10 wsl2 +Ubuntu+redis+pickle实现股票行情极速读写
BEVDet4D: Exploit Temporal Cues in Multi-camera 3D Object Detection Paper Notes
Blast!ByteDance successfully landed, only because the interview questions of LeetCode algorithm were exhausted
随机推荐
Error: Rule can only have one resource source (provided resource and test + include + exclude)
[Advanced Digital IC Verification] Difference and focus analysis between SoC system verification and IP module verification
LeetCode·每日一题·640.求解方程·模拟构造
DNS欺骗-教程详解
借数据智能,亚马逊云科技助力企业打造品牌内生增长力
递归递推之Fighting_小银考呀考不过四级
[target detection] small script: extract training set images and labels and update the index
The recursive recursive Fighting_ silver study ah but level 4
这一次,话筒给你:向自由软件之父斯托曼 提问啦!
接口自动化测试基础篇
Redis上云迁移实践
AWS Security Fundamentals
Matrix Keyboard & Calculator Small Project Based on 51 (UcosII)
ABAP file operations involved in the Chinese character set of problems and solutions for trying to read
Open Office XML 格式里如何描述多段具有不同字体设置的段落
简单的写一个防抖跟节流
【ECCV 2022|Millions of Prizes】PSG Competition: Pursuing the "Most Comprehensive" Scene Understanding
锂电池技术
mSystems | Zhongnong Wang Jie Group Reveals the Mechanisms Affecting Soil "Plastic Interstitial" Microbial Communities
C# error The 'xmins' attribute is not supported in this context