力扣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;
      }
  };
相关推荐
June bug15 分钟前
【雅思】口语概述和答题思路
职场和发展·学习方法
MATLAB代码顾问18 分钟前
【智能优化】无穷优化算法(INFO)原理与Python实现
开发语言·python·算法
炽烈小老头20 分钟前
【每天学习一点算法 2026/05/10】合并K个排序链表
学习·算法·链表
SilentSamsara30 分钟前
迭代器协议:`__iter__` / `__next__` 的完整执行流程
开发语言·人工智能·python·算法·机器学习
AI科技星30 分钟前
算法联盟ROOT · 全域数学物理卷第20、21、22分册:量子纠缠、隐形场论与时间膨胀
人工智能·算法·数学建模·数据挖掘·机器人
MATLAB代码顾问1 小时前
【智能优化】鹈鹕优化算法(POA)原理与Python实现
开发语言·python·算法
AI科技星1 小时前
微积分:变化与累积的数学(分层大白话解释版)
人工智能·算法·数学建模·数据挖掘·机器人
sinat_286945191 小时前
llm wiki
人工智能·算法·chatgpt
Kiyra1 小时前
Agent 的记忆不是存数据库就行:上下文预算与轻量记忆的设计实战
数据库·人工智能·后端·面试·职场和发展·哈希算法
博界IT精灵2 小时前
图的遍历(哈喜老师)
数据结构·考研·算法·深度优先