力扣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;
      }
  };
相关推荐
奋发向前wcx18 分钟前
CSP-J复赛模拟赛2 王晨旭补题 2026.10.3
算法
All for pursuit.32 分钟前
【回溯-5】78.子集
数据结构·c++·算法·leetcode
蒲公英eric1 小时前
Python工具链与LaTeX排版:把兵器配齐
人工智能·python·算法·数学建模·数学建模工具
别动我齐刘海1 小时前
简历技术栈全面复习总结
c++·人工智能·深度学习·学习·tcp/ip·算法·rpc
hetao17338371 小时前
2026-10-03 hetao1733837 的刷题记录
c++·算法
小南家的青蛙1 小时前
PMP刷题笔记
职场和发展·pmp考试
这张生成的图像能检测吗2 小时前
(论文速读)Object-Driven Multi-Layer Scene Decomposition:从单张图像恢复遮挡后的多层场景
人工智能·算法·计算机视觉·rgb-d·场景分解
嘎嘎风2 小时前
MiniMind 学习笔记之 01 一个 64M 的模型,凭什么像 ChatGPT?
算法
Evand J2 小时前
【MATLAB例程】三维快速扩展随机树(RRT)路径规划与到达角(AOA)定位算法|三维避障+定位仿真。附下载链接
开发语言·算法·matlab·路径规划·定位
漂流瓶jz2 小时前
UVA-1610 聚会游戏 题解答案代码 算法竞赛入门经典第二版
数据结构·c++·算法·题解·aoapc·算法竞赛入门经典·uva