当前位置:网站首页>LeetCode 739. 每日温度
LeetCode 739. 每日温度
2022-07-06 06:02:00 【Sasakihaise_】
【单调栈】
class Solution {
// 单调栈 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;
}
}
边栏推荐
- Overview of three core areas of Mathematics: geometry
- Testing and debugging of multithreaded applications
- 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
- Web服务连接器:Servlet
- 误差的基本知识
- c语言——冒泡排序
- 查詢生產訂單中某個(些)工作中心對應的標准文本碼
- 【Postman】Monitors 监测API可定时周期运行
- Implementation of linked list in address book management system
- MIT6.s081-2020 Lab2 System Calls
猜你喜欢
Web服务连接器:Servlet
(5) Explanation of yolo-v3 core source code (3)
Function of activation function
请求转发与重定向
Hongliao Technology: Liu qiangdong's "heavy hand"
华为BFD的配置规范
【eolink】PC客户端安装
Buuctf-[[gwctf 2019] I have a database (xiaoyute detailed explanation)
Gtest之TEST宏的用法
Investment strategy discussion and market scale prediction report of China's solid state high power amplifier industry from 2022 to 2028
随机推荐
ContentType的作用
进程和线程的理解
多线程应用的测试与调试
异常检测方法总结
假设检验学习笔记
C language bubble sort
H3C S5820V2_ Upgrade method after stacking IRF2 of 5830v2 switch
養了只小猫咪
SQLMAP使用教程(三)实战技巧二
Basic knowledge of error
Application du Groupe Li dans gtsam
Demander le Code de texte standard correspondant à un centre de travail dans l'ordre de production
【Postman】Monitors 监测API可定时周期运行
About PHP startup, mongodb cannot find the specified module
HCIA review
Report on the competition status and investment decision recommendations of Guangxi hospital industry in China from 2022 to 2028
Function of activation function
数字三角形模型 AcWing 1015. 摘花生
Leetcode 701 insertion operation in binary search tree -- recursive method and iterative method
Cannot build artifact 'test Web: War expanded' because it is included into a circular depend solution