当前位置:网站首页>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 下雨、下雪本是很好玩的事,大了之后也不尽然,出行、生产、工作都会受到影响
边栏推荐
- 【ECCV 2022|Millions of Prizes】PSG Competition: Pursuing the "Most Comprehensive" Scene Understanding
- M²BEV: Multi-Camera Joint 3D Detection and Segmentation with Unified Bird’s-Eye View Representation
- C# InitializeComponent() does not exist in the current context
- Network Saboteur
- 一汽奥迪:持续34年聚焦品质与体验 立足市场需求推进产品迭代
- Makefile missing separator. Stop.怎么解决「建议收藏」
- A unit test report for CRM One Order Application log
- X5WebView使用
- Calculate the number of combinations recursively
- Short read or OOM loading DB. Unrecoverable error, aborting now
猜你喜欢
3DS MAX batch export file script MAXScript with interface
Basic knowledge of switches
记录几道整型提升的题目
【目标检测】小脚本:提取训练集图片与标签并更新索引
日志@Slf4j介绍使用及配置等级
Ethernet channel Ethernet channel
神经网络可视化有3D版本了,美到沦陷!(已开源)
M²BEV: Multi-Camera Joint 3D Detection and Segmentation with Unified Bird’s-Eye View Representation
BEVDet4D: Exploit Temporal Cues in Multi-camera 3D Object Detection Paper Notes
Reversing words in a string in LeetCode
随机推荐
用低代码驱动IT现代化
Error: Rule can only have one resource source (provided resource and test + include + exclude)
A method that can make large data clustering 2000 times faster
需要被记录的OpenStack相关的命令_自己用
学习日记8
Code Casual Recording Notes_Dynamic Programming_70 Climbing Stairs
领域驱动实践总结(基本理论总结与分析V+架构分析与代码设计+具体应用设计分析)
一个 CRM One Order Application log 的单元测试报表
MySQL interview questions
ABAP file operations involved in the Chinese character set of problems and solutions for trying to read
高数_证明_曲率公式
Requirements for the construction of Loudi stem cell preparation laboratory
Makefile missing separator. Stop.怎么解决「建议收藏」
Wirshark common operations and tcp three-way handshake process example analysis
YTU 2295: KMP模式匹配 一(串)
data product manager
八大排序总是忘?快来这里~
C#报错 The ‘xmins‘ attribute is not supported in this context
SenseTime self-developed robotic arm, the first product is an AI chess-playing robot: Guo Jingjing is also invited as an endorsement
X5WebView使用