当前位置:网站首页>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;
}
}
边栏推荐
- Simulation volume leetcode [general] 1062 Longest repeating substring
- On weak network test of special test
- 對數據安全的思考(轉載)
- Digital triangle model acwing 1015 Picking flowers
- Selenium source code read through · 9 | desiredcapabilities class analysis
- Basic knowledge of MySQL
- 模拟卷Leetcode【普通】1447. 最简分数
- LeetCode 1200. 最小绝对差
- [postman] the monitors monitoring API can run periodically
- Postman core function analysis - parameterization and test report
猜你喜欢

黑猫带你学UFS协议第4篇:UFS协议栈详解

10m25dcf484c8g (FPGA) amy-6m-0002 BGA GPS module

JWT-JSON WEB TOKEN

Pat (Grade B) 2022 summer exam

Mise en œuvre d’une fonction complexe d’ajout, de suppression et de modification basée sur jeecg - boot

数据库-当前读与快照读

记一个基于JEECG-BOOT的比较复杂的增删改功能的实现

ICLR 2022 spotlight | analog transformer: time series anomaly detection method based on correlation difference

【无App Push 通用测试方案

SourceInsight Chinese garbled
随机推荐
leetcode 24. 两两交换链表中的节点
Réflexions sur la sécurité des données (réimpression)
win10无法操作(删除、剪切)文件
Full link voltage measurement: building three models
Basic knowledge of MySQL
Idea new UI usage
keil MDK中删除添加到watch1中的变量
曼哈顿距离和-打印菱形
把el-tree选中的数组转换为数组对象
Technology sharing | common interface protocol analysis
模拟卷Leetcode【普通】1314. 矩阵区域和
Simulation volume leetcode [general] 1061 Arrange the smallest equivalent strings in dictionary order
Remember the implementation of a relatively complex addition, deletion and modification function based on jeecg-boot
模拟卷Leetcode【普通】1296. 划分数组为连续数字的集合
黑猫带你学UFS协议第18篇:UFS如何配置逻辑单元(LU Management)
Data type of MySQL
[API interface tool] Introduction to postman interface
Coordinatorlayout+nestedscrollview+recyclerview pull up the bottom display is incomplete
PHP uses redis to implement distributed locks
Simulation volume leetcode [general] 1314 Matrix area and