当前位置:网站首页>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;
}
}
边栏推荐
猜你喜欢
MPLS test report
Market development prospect and investment risk assessment report of China's humidity sensor industry from 2022 to 2028
Request forwarding and redirection
PAT(乙级)2022年夏季考试
关于 PHP 启动 MongoDb 找不到指定模块问题
华为路由器如何配置静态路由
LAN communication process in the same network segment
Seven imperceptible truths in software testing
H3C V7版本交换机配置IRF
P问题、NP问题、NPC问题、NP-hard问题详解
随机推荐
Eigen sparse matrix operation
The difference and usage between continue and break
Seven imperceptible truths in software testing
Idea new UI usage
华为路由器如何配置静态路由
LAN communication process in the same network segment
授予渔,从0开始搭建一个自己想要的网页
continue和break的区别与用法
Hongliao Technology: how to quickly improve Tiktok store
GTSAM中李群的運用
HCIA review
Query the standard text code corresponding to a work center (s) in the production order
PAT(乙级)2022年夏季考试
Interface test: what are the components of the URL in fiddler
Significance of unit testing
Practice sharing: how to safely and quickly migrate from CentOS to openeuler
请求转发与重定向
Hongliao Technology: Liu qiangdong's "heavy hand"
Huawei BFD configuration specification
数学三大核心领域概述:几何