当前位置:网站首页>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;
}
}
边栏推荐
- 模拟卷Leetcode【普通】1405. 最长快乐字符串
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- Hypothesis testing learning notes
- Web界面元素的测试
- LeetCode 729. 我的日程安排表 I
- Testing of web interface elements
- Simulation volume leetcode [general] 1062 Longest repeating substring
- The whole process realizes the single sign on function and the solution of "canceltoken" of undefined when the request is canceled
- 把el-tree选中的数组转换为数组对象
- Database - current read and snapshot read
猜你喜欢
How to extract login cookies when JMeter performs interface testing
Pat (Grade B) 2022 summer exam
[Tera term] black cat takes you to learn TTL script -- serial port automation skill in embedded development
Left matching principle of joint index
E - food chain
Basic knowledge of error
[wechat applet] build a development tool environment
浅谈专项测试之弱网络测试
调用链监控Zipkin、sleuth搭建与整合
MFC关于长字符串unsigned char与CString转换及显示问题
随机推荐
B - The Suspects
「 WEB测试工程师 」岗位一面总结
Caused by:org. gradle. api. internal. plugins . PluginApplicationException: Failed to apply plugin
这些年用Keil遇到的坑
Online and offline problems
Properties file
Simulation volume leetcode [general] 1061 Arrange the smallest equivalent strings in dictionary order
Play video with Tencent video plug-in in uni app
Postman核心功能解析-参数化和测试报告
Technology sharing | common interface protocol analysis
黑猫带你学UFS协议第18篇:UFS如何配置逻辑单元(LU Management)
mysql按照首字母排序
Simulation volume leetcode [general] 1062 Longest repeating substring
JWT-JSON WEB TOKEN
Simulation volume leetcode [general] 1296 Divide an array into a set of consecutive numbers
Simulation volume leetcode [general] 1219 Golden Miner
Summary of anomaly detection methods
win10无法操作(删除、剪切)文件
模拟卷Leetcode【普通】1109. 航班预订统计
leaflet 地图