力扣HOT100 - 739. 每日温度

解题思路:

单调栈

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

相关推荐

  1. 【LeetCode739每日温度

    2024-05-12 05:00:05       61 阅读
  2. Leetcode 739. 每日温度

    2024-05-12 05:00:05       53 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-05-12 05:00:05       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-05-12 05:00:05       101 阅读
  3. 在Django里面运行非项目文件

    2024-05-12 05:00:05       82 阅读
  4. Python语言-面向对象

    2024-05-12 05:00:05       91 阅读

热门阅读

  1. 前端主题切换的多种方式

    2024-05-12 05:00:05       32 阅读
  2. 巩固学习4

    2024-05-12 05:00:05       29 阅读
  3. TS学习-抽象类和静态成员

    2024-05-12 05:00:05       30 阅读
  4. 力扣刷题笔记(1)两数之和(C++)

    2024-05-12 05:00:05       31 阅读
  5. TypeScript

    2024-05-12 05:00:05       32 阅读
  6. muduo库的使用

    2024-05-12 05:00:05       36 阅读
  7. 项目环境准备

    2024-05-12 05:00:05       34 阅读
  8. git mv命令不会自动建立目录的坑

    2024-05-12 05:00:05       98 阅读
  9. stylus详解与引入

    2024-05-12 05:00:05       33 阅读