力扣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;
      }
  };
相关推荐
周末也要写八哥1 小时前
经典算法实例:游戏中弱角色的数量(二)
算法
是Yu欸1 小时前
鸿蒙PC移植:2048 从网页小游戏到 AI 桌面应用
大数据·人工智能·算法·数据挖掘·openharmony·codex
鹿角片ljp2 小时前
KV Cache 解析
java·算法
liliangcsdn2 小时前
IVOL与偏度因子的对比测量分析
算法
threerocks3 小时前
Jev 入门第一课
算法
西柚研究生1234564 小时前
论文分析17:YOLOv11_UAVNet:无人机航拍图像专用目标检测算法
人工智能·python·深度学习·算法·目标检测
hetao17338375 小时前
2026-09-17 hetao1733837 的刷题记录
c++·算法
午彦琳6 小时前
2026.9.17
数据结构·算法·leetcode
木井巳6 小时前
【记忆化搜索】不同路径
java·算法·leetcode·深度优先·剪枝·推荐算法
怕浪猫7 小时前
从 Windows 换到 Mac 三个月,我真香了
算法·面试·架构