3676. 碗子数组的数目

文章目录

题意

题目链接

思路

单调栈

代码

C++ 复制代码
class Solution {
public:
    long long bowlSubarrays(vector<int>& nums) {
        
        int ans = 0;
        stack<int> s;
        for (int i = 0; i < nums.size(); i++) {
            const int x = nums[i];
            while (!s.empty() && nums[s.top()] < x) {
                if (i - s.top() > 1)
                    ans ++;
                s.pop();
            } 
            if (!s.empty() && i - s.top() > 1)
                ans++;
            s.push(i);
        }
        return ans;
    }
};
相关推荐
罗西的思考1 小时前
【OpenClaw具身硬件】MiniClaw 阅读笔记---(1)基础
人工智能·算法·机器学习
五仁烧饼2 小时前
Unity Addressables 静默资源策略
游戏·unity·addressables
蛋先生DX2 小时前
大模型参数存储格式揭秘:BF不是男朋友
深度学习·算法·llm
爱跳舞的烤冷面3 小时前
自学嵌入式第22天(数据结构——哈希)
数据结构·算法·哈希算法
猎嘤一号3 小时前
博弈论(Game Theory)的理论、算法与工程
人工智能·算法·安全·博弈论
月光船幽幽3 小时前
影子模式下保护 logits 不被修改
人工智能·python·算法
马拉AI3 小时前
腾讯开源 Agent 记忆系统,AI“换对话就忘”的问题有了新解法(附安装使用教程)
人工智能·算法·开源·科研
地平线开发者5 小时前
征程6工具链模型X86推理方式说明
算法
地平线开发者5 小时前
【征程6】校准量化中HistogramObserver解析
算法
OuO-25 小时前
笔试强训 Day 34:ISBN 号码、kotori 和迷宫、矩阵最长递增路径
java·算法·矩阵