当前位置:网站首页>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
边栏推荐
- Ethernet channel Ethernet channel
- OpenStack-related commands that need to be recorded _ self-use
- bgp双平面实验 路由策略控制流量
- 3DS MAX batch export file script MAXScript with interface
- Error: Rule can only have one resource source (provided resource and test + include + exclude)
- 发送post请求前台无法获取数据
- 高数_证明_曲率公式
- 安装mysql报错处理
- 广东10个项目入选工信部2021年物联网示范项目名单
- Data product manager thing 2
猜你喜欢
如何完成新媒体产品策划?
1W字详解线程本地存储 ThreadLocal
3DS MAX batch export file script MAXScript with interface
生成树协议STP(Spanning Tree Protocol)
[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
【ECCV 2022|百万奖金】PSG大赛:追求“最全面”的场景理解
Nanodlp v2.2/v3.0 light curing circuit board, connection method of mechanical switch/photoelectric switch/proximity switch and system state level setting
3DS MAX 批量导出文件脚本 MAXScript 带界面
Code Casual Recording Notes_Dynamic Programming_70 Climbing Stairs
随机推荐
Open Office XML 格式里如何描述多段具有不同字体设置的段落
【JS高级】ES5标准规范之创建子对象以及替换this_10
鸿蒙开发从hello world开始
【目标检测】小脚本:提取训练集图片与标签并更新索引
文件系统设计
这一次,话筒给你:向自由软件之父斯托曼 提问啦!
AWS 安全基础知识
Circle 创始人回应美财政部禁止 Tornado :隐私与安全之间关系紧张
[target detection] small script: extract training set images and labels and update the index
汉字检测和关键词检测
A method that can make large data clustering 2000 times faster
CodeForces - 811A
高数_证明_曲率公式
M²BEV: Multi-Camera Joint 3D Detection and Segmentation with Unified Bird’s-Eye View Representation
记录几道整型提升的题目
Error: Rule can only have one resource source (provided resource and test + include + exclude)
领域驱动实践总结(基本理论总结与分析V+架构分析与代码设计+具体应用设计分析)
【ECCV 2022|百万奖金】PSG大赛:追求“最全面”的场景理解
3DS MAX batch export file script MAXScript with interface
OpenStack-related commands that need to be recorded _ self-use