题目链接
注意事项
使用单调栈
代码
class StockSpanner {
public:
StockSpanner() {
this->stk.emplace(-1, INT_MAX);
this->idx = -1;
}
int next(int price) {
idx++;
while (price >= stk.top().second) {
stk.pop();
}
int ret = idx - stk.top().first;
stk.emplace(idx, price);
return ret;
}
private:
stack<pair<int, int>> stk;
int idx;
};
标签:901,idx,int,price,stk,股票价格,跨度,LeetCode
From: https://www.cnblogs.com/shixuanliu/p/16817971.html