美文网首页
739. 每日温度

739. 每日温度

作者: 漫行者_ | 来源:发表于2021-09-10 12:50 被阅读0次

739. 每日温度

单调栈的特点:

  • 栈内递增或者递减
  • 遇见不符合的数据是栈内数据第一次在右边遇见不满足趋势的数据

本题才用严格单调递减来做,所以栈内遇见不满足的数据,就是第一个会碰到的数据。

class Solution {
    public int[] dailyTemperatures(int[] temperatures) {
        Stack<Integer> stack = new Stack<>();
        int[] array = new int[temperatures.length];
        for(int i=0; i<temperatures.length; i++) {
            int num = temperatures[i];
            while(!stack.isEmpty() && temperatures[stack.peek()] < num) {
                array[stack.peek()] = i - stack.peek();
                stack.pop();
            }
            stack.push(i);
        }
        return array;
    }
}

相关文章

  • 739. 每日温度

    739. 每日温度[https://leetcode.cn/problems/daily-temperatures...

  • 739. 每日温度

    739. 每日温度[https://leetcode-cn.com/problems/daily-temperat...

  • 739. 每日温度

    739. 每日温度[https://leetcode-cn.com/problems/daily-temperat...

  • 题739

    739. 每日温度[https://leetcode-cn.com/problems/daily-temperat...

  • LeetCode 739. 每日温度 | Python

    739. 每日温度 题目来源:力扣(LeetCode)https://leetcode-cn.com/proble...

  • 739. 每日温度/46. 全排列

    739. 每日温度 相关标签 : 哈希表 栈 46. 全排列 相关标签: 回溯算法

  • 739. 每日温度

    根据每日 气温 列表,请重新生成一个列表,对应位置的输入是你需要再等待多久温度才会升高的天数。如果之后都不会升高,...

  • 739. 每日温度

    根据每日 气温 列表,请重新生成一个列表,对应位置的输入是你需要再等待多久温度才会升高的天数。如果之后都不会升高,...

  • 739. 每日温度

    题目描述 根据每日 气温 列表,请重新生成一个列表,对应位置的输入是你需要再等待多久温度才会升高的天数。如果之后都...

  • 739. 每日温度

    题目描述: 根据每日 气温 列表,请重新生成一个列表,对应位置的输入是你需要再等待多久温度才会升高超过该日的天数。...

网友评论

      本文标题:739. 每日温度

      本文链接:https://www.haomeiwen.com/subject/ydngwltx.html