当前位置:网站首页>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 下雨、下雪本是很好玩的事,大了之后也不尽然,出行、生产、工作都会受到影响
边栏推荐
- Efficient and Robust 2D-to-BEV Representation Learning via Geometry-guided Kernel Transformer Paper Notes
- C# WPF image is displayed without problems, but the solution does not display the image at runtime
- tampercfg内核模块导致机器频繁crash
- YTU 2295: KMP pattern match one (string)
- Loudi Center for Disease Control and Prevention Laboratory Design Concept Description
- [Advanced Digital IC Verification] Difference and focus analysis between SoC system verification and IP module verification
- Requirements for the construction of Loudi stem cell preparation laboratory
- Stream通过findFirst()查找满足条件的一条数据
- Open source SPL wipes out tens of thousands of database intermediate tables
- 什么?你还不会JVM调优?
猜你喜欢

A unit test report for CRM One Order Application log

生成树协议STP(Spanning Tree Protocol)

【目标检测】小脚本:提取训练集图片与标签并更新索引

如何完成新媒体产品策划?

交换机的基础知识

【ECCV 2022|Millions of Prizes】PSG Competition: Pursuing the "Most Comprehensive" Scene Understanding

接口自动化测试基础篇

Redis 定长队列的探索和实践

ABAP file operations involved in the Chinese character set of problems and solutions for trying to read

广东10个项目入选工信部2021年物联网示范项目名单
随机推荐
recursive recursive function
大佬们有遇到过这个问题吗? MySQL 2.2 和 2.3-SNAPSHOT 都这样,貌似是
Redis上云迁移实践
R语言使用gt包和gtExtras包优雅地、漂亮地显示表格数据:gtExtras包的gt_highlight_rows函数高亮(highlight)表格中特定的数据行、配置高亮行的特定数据列数据加粗
想问下大佬们 ,cdc oracle初始化一张300万的表任务运行着后面就这个错 怎么解决哇
the height of the landscape
mSystems | Zhongnong Wang Jie Group Reveals the Mechanisms Affecting Soil "Plastic Interstitial" Microbial Communities
C#报错 The ‘xmins‘ attribute is not supported in this context
八大排序总是忘?快来这里~
2022 Recruitment Notice for Academician Zhao Guoping Group of Shenzhen Institute of Advanced Technology, Chinese Academy of Sciences
[JS Advanced] Creating sub-objects and replacing this_10 in ES5 standard specification
Wirshark common operations and tcp three-way handshake process example analysis
系统架构系列文章三--解决传统企业核心系统的性能问题
作业8.9 构建TCP协议的服务器
Redis 定长队列的探索和实践
【219】慕课三千多的那个go工程师的培训课笔记 02 go语言的编程思想
Short read or OOM loading DB. Unrecoverable error, aborting now
Makefile missing separator. Stop.怎么解决「建议收藏」
[Study Notes] Persistence of Redis
【ECCV 2022|百万奖金】PSG大赛:追求“最全面”的场景理解