LeetCode739. Daily Temperatures
题目:
Given a list of daily temperatures
, produce a list that, for each day in the input, tells you how many days you would have to wait until a warmer temperature. If there is no future day for which this is possible, put 0
instead.
For example, given the list temperatures = [73, 74, 75, 71, 69, 72, 76, 73]
, your output should be [1, 1, 4, 2, 1, 1, 0, 0]
.
Note: The length of temperatures
will be in the range [1, 30000]
. Each temperature will be an integer in the range [30, 100]
.
题目分析:
c++代码:
class Solution {
public: vector<int> dailyTemperatures(vector<int>& temperatures) { stack<pair<int, int>> rest; vector<int> res(temperatures.size(), 0); for(int i = 0; i < temperatures.size(); ++i) { if(!res.empty()) { while(!rest.empty()) { pair<int, int> r = rest.top(); if(r.second >= temperatures[i]) break; rest.pop(); res[r.first] = (i - r.first); } } rest.push(make_pair(i, temperatures[i])); } return res; }
};
LeetCode739. Daily Temperatures相关推荐
- 739. Daily Temperatures
为什么80%的码农都做不了架构师?>>> Description Tag:Stack, Hash Table Difficulty: Medium Given a list o ...
- 739. Daily Temperatures - LeetCode
Question 739. Daily Temperatures Solution 题目大意:比今天温度还要高还需要几天 思路:笨方法实现,每次遍历未来几天,比今天温度高,就坐标减 Java实现: p ...
- 69.Daily Temperatures(日常气温)
Level: Medium 题目描述: Given a list of daily temperatures T, return a list such that, for each day in ...
- LeetCode #739 - Daily Temperatures
题目描述: Given a list of daily temperatures T, return a list such that, for each day in the input, tell ...
- 单调队列 Monotonic Queue / 单调栈 Monotonic Stack
2018-11-16 22:45:48 一.单调队列 Monotone Queue 239. Sliding Window Maximum 问题描述: 问题求解: 本题是一个经典的可以使用双端队列或者 ...
- python 特征工程_[译] 基于时序数据的特征工程 --- Python实现
基于时序数据的回归预测问题,在工作中经常遇到的.它与一般的监督学习的回归模型的区别在于数据本身是基于时序的.而常用的时序预测模型,比如arima等,添加其他特征时又不方便,不得不求助于经典的监督学习预 ...
- leetcode刷题规划
LeetCode精华题目列表[刷题规划系列] – TuringPlanet 目录 算法题到底在考察什么? 题目列表 Array String Linked List Queue Stack Advan ...
- LeetCode github集合,附CMU大神整理笔记
Github LeetCode集合 本人所有做过的题目都写在一个java项目中,同步到github中了,算是见证自己的进步.github目前同步的题目是2020-09-17日之后写的题.之前写过的题会 ...
- 基于数据挖掘的共享单车骑行数据分析与预测
温馨提示:文末有 CSDN 平台官方提供的博主 Wechat / QQ 名片 :) 1. 项目背景 共享单车系统在大城市越来越流行,通过提供价格合理的自行车租赁,让人们可以享受在城市里骑自行车的乐趣, ...
最新文章
- 数据中心在颠覆性全球经济中的重要作用
- 如何开启linux的dhcp服务器,怎么开启DHCP服务器啊
- 数字信号处理的fpga实现_FPGA数字信号处理:通信类I/Q信号及产生
- css3 操作动画要点
- 动手为王:由一条UPDATE语句引发的一波三折深入实践(含PPT)
- 数组可以容纳多少水----------给你出道题
- 利用函数指针实现累加
- 计算机二级Java考试心得
- 计算机的内存储器的最大特点是,随机存取存储器(RAM)的最大特点是
- “免费代理IP” 又双叒叕来了,这次无限量、更稳定。(附带使用教程)
- 阿里云主机修改操作系统 详细步骤
- 电视台工作计算机管理,电视台工作岗位有哪些
- 关于vue弹窗自定义
- linux界面任务栏平铺,可能是linux 4.9.8的问题-安装15.4后桌面没有任务栏
- 【美文欣赏】给爱子的信
- serialize()序列化
- 2017阿里研发工程师C/C++实习生招聘笔试题
- Python爬虫+BI分析,做一份酷炫的A股牛市可视化!
- P2P网贷平台系统市场占有率排行榜
- 关于硕士研究生延毕的几问几答