当前位置:网站首页>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【普通】1405. 最长快乐字符串
- Thoughts on data security (Reprint)
- Manhattan distance sum - print diamond
- Cannot create PoolableConnectionFactory (Could not create connection to database server. 错误
- JWT-JSON WEB TOKEN
- org.activiti.bpmn.exceptions.XMLException: cvc-complex-type.2.4.a: 发现了以元素 ‘outgoing‘ 开头的无效内容
- 对数据安全的思考(转载)
- The whole process realizes the single sign on function and the solution of "canceltoken" of undefined when the request is canceled
- Selenium source code read through · 9 | desiredcapabilities class analysis
- 模拟卷Leetcode【普通】1061. 按字典序排列最小的等效字符串
猜你喜欢
[Tera term] black cat takes you to learn TTL script -- serial port automation skill in embedded development
[API interface tool] Introduction to postman interface
[C language] string left rotation
[wechat applet] build a development tool environment
【MQTT从入门到提高系列 | 01】从0到1快速搭建MQTT测试环境
[eolink] PC client installation
曼哈顿距离与曼哈顿矩形-打印回字型矩阵
在uni-app中使用腾讯视频插件播放视频
G - Supermarket
Redis core technology and basic architecture of actual combat: what does a key value database contain?
随机推荐
LeetCode 1200. 最小绝对差
Qt:无法定位程序输入点XXXXX于动态链接库。
Simulation volume leetcode [general] 1414 The minimum number of Fibonacci numbers with a sum of K
技术分享 | 常见接口协议解析
10M25DCF484C8G(FPGA) AMY-6M-0002 BGA GPS模块
Simulation volume leetcode [general] 1218 Longest definite difference subsequence
[postman] dynamic variable (also known as mock function)
Properties file
模拟卷Leetcode【普通】1296. 划分数组为连续数字的集合
JDBC Requset 对应内容及功能介绍
Summary of the post of "Web Test Engineer"
Past and present lives of QR code and sorting out six test points
MFC关于长字符串unsigned char与CString转换及显示问题
还在为如何编写Web自动化测试用例而烦恼嘛?资深测试工程师手把手教你Selenium 测试用例编写
Is the test cycle compressed? Teach you 9 ways to deal with it
Resttemplate and feign realize token transmission
Simulation volume leetcode [general] 1405 Longest happy string
leaflet 地图
Simulation volume leetcode [general] 1447 Simplest fraction
Summary of anomaly detection methods