当前位置:网站首页>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;
}
}
边栏推荐
- MySQL之数据类型
- Simulation volume leetcode [general] 1414 The minimum number of Fibonacci numbers with a sum of K
- Career advancement Guide: recommended books for people in big factories
- [postman] test script writing and assertion details
- 自定义指定路由上的Gateway过滤器工厂
- Cannot create poolableconnectionfactory (could not create connection to database server. error
- PHP uses redis to implement distributed locks
- Isam2 and incrementalfixedlagsmooth instructions in gtsam
- 浅谈专项测试之弱网络测试
- Black cat takes you to learn UFS Protocol Part 8: UFS initialization (boot operation)
猜你喜欢
D - How Many Answers Are Wrong
MFC关于长字符串unsigned char与CString转换及显示问题
Hypothesis testing learning notes
Convert the array selected by El tree into an array object
oscp raven2靶机渗透过程
数据库隔离级别
[no app push general test plan
Career advancement Guide: recommended books for people in big factories
Play video with Tencent video plug-in in uni app
F - True Liars (种类并查集+DP)
随机推荐
Caused by:org. gradle. api. internal. plugins . PluginApplicationException: Failed to apply plugin
The whole process realizes the single sign on function and the solution of "canceltoken" of undefined when the request is canceled
黑猫带你学UFS协议第18篇:UFS如何配置逻辑单元(LU Management)
記一個基於JEECG-BOOT的比較複雜的增删改功能的實現
MFC on the conversion and display of long string unsigned char and CString
JDBC Requset 对应内容及功能介绍
JDBC requset corresponding content and function introduction
PHP uses redis to implement distributed locks
[C language] qsort function
ESP32 ESP-IDF看门狗TWDT
Construction and integration of Zipkin and sleuth for call chain monitoring
Black cat takes you to learn EMMC Protocol Part 10: EMMC read and write operation details (read & write)
私人云盘部署
【无App Push 通用测试方案
Cannot create PoolableConnectionFactory (Could not create connection to database server. 错误
在uni-app中使用腾讯视频插件播放视频
Full link voltage measurement: building three models
Win10 cannot operate (delete, cut) files
leetcode 24. 两两交换链表中的节点
Isam2 and incrementalfixedlagsmooth instructions in gtsam