当前位置:网站首页>leetcode 739. Daily Temperatures Daily Temperatures (Moderate)
leetcode 739. Daily Temperatures Daily Temperatures (Moderate)
2022-08-10 13:53:00 【InfoQ】
I. The main idea of the title
- 1 <= temperatures.length <= 105
- 30 <= temperatures[i] <= 100
Second, problem solving ideas
- What is a monotonic stack?Monotonic stacks handle problems requiring size comparisons in overall O(n) time by maintaining monotonically increasing (decreasing) properties of the values in the stack.
Three, problem solving method
3.1 Java implementation
public class Solution {
public int[] dailyTemperatures(int[] temperatures) {
int[] ans = new int[temperatures.length];
Stack 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;
}
}
Fourth, Summary Notes
- 2022/8/10 Rain and snow are fun things, but it's not always the same after getting older. Travel, production, and work will be affected
边栏推荐
猜你喜欢
Error: Rule can only have one resource source (provided resource and test + include + exclude)
MySQL interview questions
【量化交易行情不够快?】一文搞定通过Win10 wsl2 +Ubuntu+redis+pickle实现股票行情极速读写
Existing in the rain of PFAS chemical poses a threat to the safety of drinking water
代码随想录笔记_动态规划_70爬楼梯
友邦人寿可观测体系设计与落地
雨水中存在的PFAS化学物质对饮用水安全构成了威胁
[Study Notes] Persistence of Redis
Cloud Migration Practice of Redis
商汤自研机械臂,首款产品是AI下棋机器人:还请郭晶晶作代言
随机推荐
Interface Automation Testing Basics
[JS Advanced] Creating sub-objects and replacing this_10 in ES5 standard specification
BEVDet4D: Exploit Temporal Cues in Multi-camera 3D Object Detection Paper Notes
开源SPL消灭数以万计的数据库中间表
Circle 创始人回应美财政部禁止 Tornado :隐私与安全之间关系紧张
SQL学习(基础)
需要被记录的OpenStack相关的命令_自己用
ABAP 里文件操作涉及到中文字符集的问题和解决方案试读版
C# error The 'xmins' attribute is not supported in this context
Network Saboteur
【219】慕课三千多的那个go工程师的培训课笔记 02 go语言的编程思想
[219] The training course notes of the go engineer with more than 3,000 MOOCs 02 Programming ideas in the go language
1W字详解线程本地存储 ThreadLocal
C#实现访问OPC UA服务器
学习日记9
【JS高级】ES5标准规范之创建子对象以及替换this_10
这一次,话筒给你:向自由软件之父斯托曼 提问啦!
数据产品经理那点事儿 一
高数_证明_曲率公式
C#报错 The ‘xmins‘ attribute is not supported in this context