力扣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;
      }
  };
相关推荐
ZPC82106 小时前
joy 及sensor_msgs
算法
Three_ST6 小时前
沐神-动手学习深度学习-习题答案4.4模型选择,欠拟合,过拟合
人工智能·python·深度学习·学习·算法
CIO_Alliance6 小时前
AI深度系列(2)| CNN卷积池化感受野原理:从局部感知到全局视野
人工智能·深度学习·线性代数·算法·计算机视觉·企业ai转型·企业cio联盟
探物 AI7 小时前
机器人清理墙角蜘蛛网,背后需要哪些算法?——从视觉分割到贴墙力控
算法·机器人
青 春 记 忆7 小时前
LeetCode 226. 翻转二叉树|Python 解法详解
python·算法·leetcode
民乐团扒谱机7 小时前
【微科普】压缩感知(CS):违反了奈奎斯特采样定理?不先采集也能还原信号?大白话讲透稀疏采样、L1重建与OMP,一文吃透附代码
python·神经网络·线性代数·算法·数学建模·压缩感知·奈奎斯特
88号技师7 小时前
2026年SCI-分数牛顿衍生优化算法Fractional Newton-derived optimizer-附Matlab免费代码
开发语言·算法·数学建模·matlab·优化算法
夏玉林的学习之路7 小时前
算法7.链式栈
算法
啊嘞嘞?7 小时前
力扣(回文链表)
算法·leetcode·链表
Awh-8 小时前
数据结构 第六章:哈希存储
数据结构·算法·哈希算法