力扣739.每日温度

力扣739.每日温度

  • 单调栈

    • 从右到左做
    • 栈中存下标
cpp 复制代码
  class Solution {
  public:
      vector<int> dailyTemperatures(vector<int>& temperatures) {
          int n = temperatures.size();
          vector<int> ans(n);
          stack<int> st;
          for(int i=n-1;i>=0;i--)
          {
              int t = temperatures[i];
              //说明他不会是任何数的右边界
              while(!st.empty() && t >= temperatures[st.top()])
                  st.pop();
              if(!st.empty())
                  ans[i] = st.top() - i;
              st.push(i);
          }
          return ans;
      }
  };
相关推荐
rannn_11114 小时前
【力扣hot100】二叉树专题+总结
java·算法·leetcode·二叉树
啊嘞嘞?14 小时前
力扣(岛屿数量)
算法·leetcode
zander25814 小时前
LeetCode 198. 打家劫舍
算法·leetcode·深度优先
吃着火锅x唱着歌14 小时前
LeetCode 648.单词替换
算法·leetcode·职场和发展
一只积极向上的小咸鱼14 小时前
分词器tokenizer
算法·llm
Elsa️74614 小时前
leetcode 14.最长公共前缀
算法·leetcode·职场和发展
不会代码的小猴14 小时前
6. Qt网络编程
开发语言·c++·笔记·qt·算法
Zguigo15 小时前
树的前序|中序|后序遍历【使用栈实现】
数据结构·算法
zhanghaha131415 小时前
HTML系列教程:4_什么是 HTML 元素(零基础超详细讲解)
前端·算法·html
TAN-90°-15 小时前
Deep Learning for Computer Vision——Training CNNs and CNN Architectures
人工智能·深度学习·神经网络·算法·机器学习·计算机视觉·cnn