当前位置:网站首页>LeetCode 739. Daily temperature
LeetCode 739. Daily temperature
2022-07-06 06:23:00 【Sasakihaise_】
【 Monotonic stack 】
class Solution {
// Monotonic stack 10:18 42
public int[] dailyTemperatures(int[] temperatures) {
Deque<Integer> stack = new LinkedList();
int[] t = temperatures;
int n = t.length;
int[] ans = new int[n];
for (var i = n - 1; i >= 0; i--) {
while (!stack.isEmpty() && t[stack.peek()] <= t[i]) {
stack.pop();
}
if (stack.isEmpty()) {
ans[i] = 0;
} else {
ans[i] = stack.peek() - i;
}
stack.push(i);
}
return ans;
}
}
边栏推荐
- Idea new UI usage
- (中)苹果有开源,但又怎样呢?
- Understanding of processes and threads
- 基于JEECG-BOOT的list页面的地址栏参数传递
- Qt:无法定位程序输入点XXXXX于动态链接库。
- 「 WEB测试工程师 」岗位一面总结
- [postman] dynamic variable (also known as mock function)
- 数据库隔离级别
- 黑猫带你学UFS协议第8篇:UFS初始化详解(Boot Operation)
- Manhattan distance and Manhattan rectangle - print back font matrix
猜你喜欢
Digital triangle model acwing 1015 Picking flowers
LeetCode 731. 我的日程安排表 II
D - How Many Answers Are Wrong
【MQTT从入门到提高系列 | 01】从0到1快速搭建MQTT测试环境
曼哈顿距离和-打印菱形
Selenium source code read through · 9 | desiredcapabilities class analysis
Data type of MySQL
keil MDK中删除添加到watch1中的变量
Manhattan distance sum - print diamond
调用链监控Zipkin、sleuth搭建与整合
随机推荐
Simulation volume leetcode [general] 1314 Matrix area and
ICLR 2022 spotlight | analog transformer: time series anomaly detection method based on correlation difference
How to extract login cookies when JMeter performs interface testing
MFC 动态创建的对话框及改变控件的大小和位置
SourceInsight Chinese garbled
把el-tree选中的数组转换为数组对象
黑猫带你学UFS协议第8篇:UFS初始化详解(Boot Operation)
联合索引的左匹配原则
Simulation volume leetcode [general] 1143 Longest common subsequence
模拟卷Leetcode【普通】1314. 矩阵区域和
【无App Push 通用测试方案
D - How Many Answers Are Wrong
[no app push general test plan
[postman] the monitors monitoring API can run periodically
自定义指定路由上的Gateway过滤器工厂
B - The Suspects
Hypothesis testing learning notes
[postman] collections configuration running process
Simulation volume leetcode [general] 1061 Arrange the smallest equivalent strings in dictionary order
JDBC Requset 对应内容及功能介绍