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;
    }
};
相关推荐
All for pursuit.37 分钟前
【位运算-3】136.只出现一次的数字
数据结构·c++·算法·leetcode
MoRanzhi120338 分钟前
106.正则问题(分治)
python·算法·正则表达式·蓝桥杯·递归·分治算法·字符串处理
suhan1 小时前
【数据结构】五、树:7.哈夫曼树、哈夫曼编码
数据结构·算法·排序算法
kkhimself1 小时前
POJ-3126
算法
suhan1 小时前
【数据结构】五、树:6.平衡二叉树AVL
数据结构·算法·排序算法
suhan1 小时前
【数据结构】五、树:5.二叉排序树BST
数据结构·算法·排序算法
爱读书的小胖2 小时前
80. 删除有序数组中的重复项 II
java·数据结构·算法
臻选云栗子2 小时前
PCDN跑不起来?先别甩锅给平台,问题可能出在这
算法·程序员
小画家~2 小时前
vue3 里面的 itemList.reduce
前端·数据结构·算法
All for pursuit.3 小时前
【完结】LeetCodeHot100题 详细解题过程及代码汇总
数据结构·c++·算法·leetcode