当前位置:网站首页>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
边栏推荐
猜你喜欢
MySQL面试题整理
M²BEV: Multi-Camera Joint 3D Detection and Segmentation with Unified Bird’s-Eye View Representation
【学习笔记】Redis的持久化
Nanodlp v2.2/v3.0 light curing circuit board, connection method of mechanical switch/photoelectric switch/proximity switch and system state level setting
【JS高级】ES5标准规范之创建子对象以及替换this_10
Open source SPL wipes out tens of thousands of database intermediate tables
高数_证明_弧微分公式
网络安全——XSS之被我们忽视的Cookie
【ECCV 2022|Millions of Prizes】PSG Competition: Pursuing the "Most Comprehensive" Scene Understanding
如何完成新媒体产品策划?
随机推荐
Stream通过findFirst()查找满足条件的一条数据
Error: Rule can only have one resource source (provided resource and test + include + exclude)
【JS高级】ES5标准规范之创建子对象以及替换this_10
Open Office XML 格式里如何描述多段具有不同字体设置的段落
神了!阿里数据库专家纯手写了这份604页的Oracle+MySQL攻坚指南
The recursive recursive Fighting_ silver study ah but level 4
Fragment的show和hide
文件系统设计
力扣解法汇总640-求解方程
ICML 2022 | 基于随机注意力机制的可解释可泛化图学习
YTU 2295: KMP模式匹配 一(串)
接口自动化测试基础篇
ABAP file operations involved in the Chinese character set of problems and solutions for trying to read
Makefile missing separator. Stop.怎么解决「建议收藏」
广东10个项目入选工信部2021年物联网示范项目名单
tampercfg内核模块导致机器频繁crash
22家!北京昌平区通报存在食品安全问题餐饮服务企业
进程和计划任务管理
简单的写一个防抖跟节流
一汽奥迪:持续34年聚焦品质与体验 立足市场需求推进产品迭代