力扣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;
      }
  };
相关推荐
SDWAN_Cheap13 小时前
SD-WAN智能选路技术的算法与实现机制
算法·php·sdwan
artificiali13 小时前
拼好卷 05
职场和发展
不会就选b13 小时前
数据结构之树&&二叉树(二)
数据结构·算法
渡之14 小时前
ArduPilot (APM)滤波器之SlewLimiter 深度解析
算法
zander25814 小时前
LeetCode 1143. 最长公共子序列
开发语言·python·算法
Sumerking14 小时前
llc_control.c 专项评审(v3 更新版)
c语言·开发语言·算法·obc
L小航呀14 小时前
代码随想录刷题 Day16
leetcode·面试
软行14 小时前
LeetCode 每日一题 3876. 构造奇偶一致的数组 II
c++·算法·leetcode
绿算技术15 小时前
Solidigm联合绿算技术共同发布《面向 SOHO AI 推理的存储扩展方案》技术白皮书
人工智能·科技·算法·架构·spark
EDPJ15 小时前
(2026|IPI|我的论文投稿中,PSP 超轻量采样算法,轻量化架构探索/早融合+头压缩)LUMIN:面向工业异常检测的轻量级通用制造检测网络
算法·计算机视觉·架构·异常检测·采样算法