当前位置:网站首页>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【普通】1314. 矩阵区域和
- 模拟卷Leetcode【普通】1219. 黄金矿工
- 模拟卷Leetcode【普通】1447. 最简分数
- LeetCode 1200. 最小绝对差
- MySQL之数据类型
- [C language] qsort function
- 基于JEECG-BOOT的list页面的地址栏参数传递
- Simulation volume leetcode [general] 1447 Simplest fraction
- Basic knowledge of error
- QT: the program input point xxxxx cannot be located in the dynamic link library.
猜你喜欢
随机推荐
私人云盘部署
Simulation volume leetcode [general] 1414 The minimum number of Fibonacci numbers with a sum of K
Full link voltage measurement: building three models
MFC关于长字符串unsigned char与CString转换及显示问题
黑猫带你学eMMC协议第10篇:eMMC读写操作详解(read & write)
Simulation volume leetcode [general] 1218 Longest definite difference subsequence
Web界面元素的测试
Black cat takes you to learn UFS protocol Chapter 4: detailed explanation of UFS protocol stack
The whole process realizes the single sign on function and the solution of "canceltoken" of undefined when the request is canceled
LeetCode 1200. 最小绝对差
模拟卷Leetcode【普通】1143. 最长公共子序列
Basic knowledge of error
Manage configuration using Nacos
曼哈顿距离与曼哈顿矩形-打印回字型矩阵
黑猫带你学UFS协议第18篇:UFS如何配置逻辑单元(LU Management)
對數據安全的思考(轉載)
Isam2 and incrementalfixedlagsmooth instructions in gtsam
G - Supermarket
【MQTT从入门到提高系列 | 01】从0到1快速搭建MQTT测试环境
Idea new UI usage








