题目大意 给你接下来每一天的气温,求出对于每一天的气温,下一次出现比它高气温的日期距现在要等多少天 解题思路 利用单调栈,维护一个单调递减的栈 将每一天的下标i入栈,维护一个温度递减的下标 若下一个温度p,比栈顶元素对应的温度p'要高,就出栈,且p就是p'的最近的“高温” 代码实现 from collections import deque class Solution: def dailyTemperatures(self, temperatures): ans = [0]*len(tempe…
Question 739. Daily Temperatures Solution 题目大意:比今天温度还要高还需要几天 思路:笨方法实现,每次遍历未来几天,比今天温度高,就坐标减 Java实现: public int[] dailyTemperatures(int[] temperatures) { int[] ans = new int[temperatures.length]; for (int i = 0; i<temperatures.length; i++) { int highId…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 解题方法 倒序遍历 栈 日期 题目地址:https://leetcode.com/problems/daily-temperatures/description/ 题目描述 Given a list of daily temperatures, produce a list that, for each day in the input, tells you how m…
题目 根据每日 气温 列表,请重新生成一个列表,对应位置的输入是你需要再等待多久温度才会升高超过该日的天数.如果之后都不会升高,请在该位置用 0 来代替. 例如,给定一个列表 temperatures = [73, 74, 75, 71, 69, 72, 76, 73],你的输出应该是 [1, 1, 4, 2, 1, 1, 0, 0]. 提示:气温 列表长度的范围是 [1, 30000].每个气温的值的均为华氏度,都是在 [30, 100] 范围内的整数. 来源:力扣(LeetCode) 链接:…
原题链接在这里:https://leetcode.com/problems/daily-temperatures/description/ 题目: 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 fu…
collections是python的高级容器类库,包含了dict.truple之外的常用容器. 下面介绍常用的deque 1. deque是双端队列,可以从两端塞元素进去,也可以从两端取元素. 2. deque是线程安全的,可以用来做多线程的共享资源,我也是因为这个开始接触duque的 >>> from collections import deque >>> a = [1, 2, 3, 4] 用列表初始化deque >>> deq = deque(…
https://leetcode.com/problems/daily-temperatures/description/ class Solution { public: vector<int> dailyTemperatures(vector<int>& temperatures) { stack<int> st; vector<int> res(temperatures.size()); ; i >= ; i--) { while (!s…
题目标签:HashMap 题目给了我们一组温度,让我们找出 对于每一天,要等多少天,气温会变暖.返回一组等待的天数. 可以从最后一天的温度遍历起,从末端遍历到开头,对于每一天的温度,把它在T里面的index存入 temp[101] 保存.然后对于每一天的温度,从温度+1 到100 全部遍历后,找出变暖温度里离当天最近的那一天.存入answer.具体看code. Java Solution: Runtime: 8 ms, faster than 91.33% Memory Usage: 42.7…
739 每日温度 ( 单调栈 ) 题目 : https://leetcode-cn.com/problems/daily-temperatures/ 题意 : 找到数组每一个元素之后第一个大于它的元素的位置 思路 : 从后往前遍历数组, 进行压栈操作, 栈中保留元素在T中的索引, 栈始终呈下大上小的状态, 对于每个遍历到的元素如果小于栈顶则输出1, 如果大于栈顶则把栈顶元素弹出知道匹配到小于的元素 核心 : 维护一个单调递减栈 ( 忘记存代码了, 嫖一份算了 class Solution { p…
2018-11-16 22:45:48 一.单调队列 Monotone Queue 239. Sliding Window Maximum 问题描述: 问题求解: 本题是一个经典的可以使用双端队列或者说单调队列完成的题目,具体来说,就是通过双端队列将可能的最大值维护起来. public int[] maxSlidingWindow(int[] nums, int k) { if (nums == null || nums.length < k || k == 0) return new int[…