力扣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;
      }
  };
相关推荐
想吃火锅100521 分钟前
【leetcode】56.合并区间js
算法·leetcode·职场和发展
imuliuliang23 分钟前
可合并堆在多任务调度中的优势与实现技巧7
算法
学究天人23 分钟前
数学公理体系大全:Comprehensive Collection of Mathematical Axiom Systems(卷6)
网络·算法·数学建模·动态规划·几何学·图论·拓扑学
wabs66630 分钟前
关于动态规划【力扣72.编辑距离的思考】
算法·leetcode·动态规划
用户333239768841 小时前
我做了一个 RepoMind:让 AI 写架构前,先去看看真实开源项目
算法
chh5631 小时前
C++--list
开发语言·数据结构·c++·学习·算法·list
killerbasd1 小时前
总结 7。10
人工智能·算法·机器学习
林间码客1 小时前
RAG系统评估指南:从入门到实践
人工智能·算法·机器学习
凌波粒1 小时前
LeetCode--47.全排列 II(回溯算法)
算法·leetcode·职场和发展
学究天人1 小时前
数学公理体系大全:Comprehensive Collection of Mathematical Axiom Systems(卷8)
线性代数·算法·机器学习·数学建模·动态规划·图论·抽象代数