当前位置:网站首页>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;
}
}
边栏推荐
- PHP uses redis to implement distributed locks
- Qt:无法定位程序输入点XXXXX于动态链接库。
- RestTemplate、Feign实现Token传递
- [C language] string left rotation
- 二维码的前世今生 与 六大测试点梳理
- Technology sharing | common interface protocol analysis
- 模拟卷Leetcode【普通】1219. 黄金矿工
- Simulation volume leetcode [general] 1109 Flight reservation statistics
- B - The Suspects
- leetcode 24. Exchange the nodes in the linked list in pairs
猜你喜欢
10M25DCF484C8G(FPGA) AMY-6M-0002 BGA GPS模块
LeetCode 739. 每日温度
Redis core technology and basic architecture of actual combat: what does a key value database contain?
数据库隔离级别
Idea new UI usage
org.activiti.bpmn.exceptions.XMLException: cvc-complex-type.2.4.a: 发现了以元素 ‘outgoing‘ 开头的无效内容
G - Supermarket
Detailed explanation of P problem, NP problem, NPC problem and NP hard problem
LeetCode 732. 我的日程安排表 III
ICLR 2022 spotlight | analog transformer: time series anomaly detection method based on correlation difference
随机推荐
Simulation volume leetcode [general] 1405 Longest happy string
D - How Many Answers Are Wrong
这些年用Keil遇到的坑
Isam2 and incrementalfixedlagsmooth instructions in gtsam
全链路压测:构建三大模型
[postman] collections configuration running process
黑猫带你学eMMC协议第10篇:eMMC读写操作详解(read & write)
Simulation volume leetcode [general] 1249 Remove invalid parentheses
Data type of MySQL
oscp raven2靶机渗透过程
JDBC Requset 对应内容及功能介绍
Past and present lives of QR code and sorting out six test points
Simulation volume leetcode [general] 1414 The minimum number of Fibonacci numbers with a sum of K
Still worrying about how to write web automation test cases? Senior test engineers teach you selenium test case writing hand in hand
Properties file
win10无法操作(删除、剪切)文件
Postman core function analysis - parameterization and test report
Detailed explanation of P problem, NP problem, NPC problem and NP hard problem
全程实现单点登录功能和请求被取消报错“cancelToken“ of undefined的解决方法
[no app push general test plan