力扣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;
      }
  };
相关推荐
阿Y加油吧7 分钟前
算法实战笔记:LeetCode 169 多数元素 & 75 颜色分类
笔记·算法·leetcode
不要秃头的小孩15 分钟前
力扣刷题——509. 斐波那契数
python·算法·leetcode·动态规划
We་ct1 小时前
LeetCode 120. 三角形最小路径和:动态规划详解
前端·javascript·算法·leetcode·typescript·动态规划
蒸汽求职1 小时前
破局“无效互面”:跨国大厂视角的工业级 Mock Interview 价值解析
缓存·面试·职场和发展·金融·notion
py有趣1 小时前
力扣热门100题之和为K的子数组
数据结构·算法·leetcode
hipolymers2 小时前
C语言怎么样?难学吗?
c语言·数据结构·学习·算法·编程
workflower3 小时前
机器人应用-楼宇室内巡逻
大数据·人工智能·算法·microsoft·机器人·动态规划·享元模式
ZPC82103 小时前
fanuc 机器人通过PR寄存器实现轨迹控制
人工智能·算法·计算机视觉·机器人
py有趣3 小时前
力扣热门100题之编辑距离
数据结构·算法·leetcode