当前位置:网站首页>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
边栏推荐
- ES5和SE6来实现一个Promise效果
- 一个 CRM One Order Application log 的单元测试报表
- 安装mysql报错处理
- Makefile missing separator. Stop.怎么解决「建议收藏」
- R语言使用gt包和gtExtras包优雅地、漂亮地显示表格数据:gtExtras包的gt_highlight_rows函数高亮(highlight)表格中特定的数据行、配置高亮行的特定数据列数据加粗
- Borg Maze (bfs+最小生成树)
- C#WPF 图片在显示时没有问题,但在运行时图片显示不出来的解决
- SecureCRTPortable – 破解
- 【JS高级】ES5标准规范之创建子对象以及替换this_10
- Have you guys encountered this problem?MySQL 2.2 and 2.3-SNAPSHOT are like this, it seems to be
猜你喜欢
bgp dual plane experiment routing strategy to control traffic
[target detection] small script: extract training set images and labels and update the index
Open Office XML 格式里如何描述多段具有不同字体设置的段落
R语言实战应用案例:论文篇(一)-特殊柱形图绘制
友邦人寿可观测体系设计与落地
2022年五大云虚拟化趋势
Wirshark common operations and tcp three-way handshake process example analysis
ABAP 里文件操作涉及到中文字符集的问题和解决方案试读版
M²BEV: Multi-Camera Joint 3D Detection and Segmentation with Unified Bird’s-Eye View Representation
Ethernet channel 以太信道
随机推荐
Network Saboteur
【MinIO】工具类使用
LeetCode·每日一题·640.求解方程·模拟构造
指针(C语言初解)
Network Saboteur
How to describe multiple paragraphs with different font settings in Open Office XML format
Interface Automation Testing Basics
MySQL - 数据库的存储引擎
CodeForces-834C
leetcode 739. Daily Temperatures 每日温度(中等)
A unit test report for CRM One Order Application log
YTU 2295: KMP pattern match one (string)
【POI 2008, BLO】割点
C# InitializeComponent() does not exist in the current context
安装mysql报错处理
Data product manager thing 2
NAACL 2022 | 简单且高效!随机中间层映射指导的知识蒸馏方法
I would like to ask the big guys, how to solve this error when cdc oracle initializes a 3 million table task running
Vivado crashes or the message is not displayed
Import other custom namespaces in C#