力扣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;
      }
  };
相关推荐
Raink老师27 分钟前
【AI面试临阵磨枪】什么是 MCP(Model Control Protocol)、A2A(Agent-to-Agent)协议?
人工智能·面试·职场和发展·ai 面试
松☆1 小时前
C++ 算法竞赛题解:P13569 [CCPC 2024 重庆站] osu!mania —— 浮点数精度陷阱与 `eps` 的深度解析
开发语言·c++·算法
久菜盒子工作室1 小时前
面试|产品经理|为什么从 xxx(主要是实习 、工作)离职?
面试·职场和发展·产品经理
jr-create(•̀⌄•́)1 小时前
正则化和优化算法区别
pytorch·深度学习·神经网络·算法
li星野3 小时前
刷题:数组
数据结构·算法
tankeven3 小时前
HJ182 画展布置
c++·算法
千寻girling3 小时前
被内推的面试 , 第一次
java·前端·python·面试·职场和发展·typescript·node.js
Java后端的Ai之路3 小时前
LangChain 面试问答指南2
面试·职场和发展·langchain
CeshirenTester3 小时前
面试紧张卡壳?别练背稿了,练“在压力下聊天”才是正解
面试·职场和发展
AC赳赳老秦3 小时前
程序员面试:OpenClaw生成面试题、模拟面试,高效备战面试
人工智能·python·机器学习·面试·职场和发展·deepseek·openclaw