当前位置:网站首页>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;
}
}
边栏推荐
- 自定义指定路由上的Gateway过滤器工厂
- Qt:无法定位程序输入点XXXXX于动态链接库。
- MFC 动态创建的对话框及改变控件的大小和位置
- G - Supermarket
- Coordinatorlayout+nestedscrollview+recyclerview pull up the bottom display is incomplete
- Aike AI frontier promotion (2.13)
- win10无法操作(删除、剪切)文件
- Simulation volume leetcode [general] 1091 The shortest path in binary matrix
- B - The Suspects
- Detailed explanation of P problem, NP problem, NPC problem and NP hard problem
猜你喜欢

Selenium source code read through · 9 | desiredcapabilities class analysis
![[API interface tool] Introduction to postman interface](/img/03/c1541fca65dd726fd4bdc8793b605e.png)
[API interface tool] Introduction to postman interface

黑猫带你学eMMC协议第10篇:eMMC读写操作详解(read & write)

Detailed explanation of P problem, NP problem, NPC problem and NP hard problem

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

联合索引的左匹配原则

Properties file

Redis 核心技术与实战之 基本架构:一个键值数据库包含什么?

LeetCode 731. 我的日程安排表 II

Manhattan distance and Manhattan rectangle - print back font matrix
随机推荐
10m25dcf484c8g (FPGA) amy-6m-0002 BGA GPS module
Detailed explanation of P problem, NP problem, NPC problem and NP hard problem
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
模拟卷Leetcode【普通】1218. 最长定差子序列
[Tera term] black cat takes you to learn TTL script -- serial port automation skill in embedded development
Customize the gateway filter factory on the specified route
Still worrying about how to write web automation test cases? Senior test engineers teach you selenium test case writing hand in hand
JMeter做接口测试,如何提取登录Cookie
在JEECG-boot代码生成的基础上修改list页面(结合自定义的组件)
Selenium source code read through · 9 | desiredcapabilities class analysis
进程和线程的理解
自定义指定路由上的Gateway过滤器工厂
Convert the array selected by El tree into an array object
黑猫带你学UFS协议第4篇:UFS协议栈详解
leetcode 24. Exchange the nodes in the linked list in pairs
职场进阶指南:大厂人必看书籍推荐
Technology sharing | common interface protocol analysis
Simulation volume leetcode [general] 1249 Remove invalid parentheses
keil MDK中删除添加到watch1中的变量
Manhattan distance and Manhattan rectangle - print back font matrix