当前位置:网站首页>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
边栏推荐
猜你喜欢

Interface Automation Testing Basics

2022-08-09:以下go语言代码输出什么?A:否,会 panic;B:是,能正确运行;C:不清楚,看投票结果。 package main import ( “fmt“ “syn

Send a post request at the front desk can't get the data

高数_证明_弧微分公式

缺少比较器,运放来救场!(运放当做比较器电路记录)

重要通知 | “移动云杯”算力网络应用创新大赛初赛延期!!

laravel 抛错给钉钉

矩阵键盘&基于51(UcosII)计算器小项目

什么?你还不会JVM调优?

Efficient and Robust 2D-to-BEV Representation Learning via Geometry-guided Kernel Transformer 论文笔记
随机推荐
C#实现访问OPC UA服务器
进程和计划任务管理
Have you guys encountered this problem?MySQL 2.2 and 2.3-SNAPSHOT are like this, it seems to be
ArcMAP has a problem of -15 and cannot be accessed [Provide your license server administrator with the following information:Err-15]
22家!北京昌平区通报存在食品安全问题餐饮服务企业
WebView的优化与常见问题解决方案
BEVDet4D: Exploit Temporal Cues in Multi-camera 3D Object Detection 论文笔记
鸿蒙开发从hello world开始
矩阵键盘&基于51(UcosII)计算器小项目
Vivado crashes or the message is not displayed
C# 当前上下文中不存在InitializeComponent()
Error: Rule can only have one resource source (provided resource and test + include + exclude)
tampercfg内核模块导致机器频繁crash
【目标检测】小脚本:提取训练集图片与标签并更新索引
DNS欺骗-教程详解
Fragment的show和hide
每个月工资表在数据库如何存储?求一个设计思路
学习日记8
广东10个项目入选工信部2021年物联网示范项目名单
日志@Slf4j介绍使用及配置等级