方法:单调栈
class StockSpanner {
public:
stack<int> st;
vector<int> prices;
vector<int> res;
StockSpanner() {
}
int next(int price) {
prices.push_back(price);
int ret = prices.size() - 1;
while(!st.empty() && price>=prices[st.top()]){
ret = res[st.top()];
st.pop();
}
st.push(prices.size()-1);
res.push_back(ret);
return prices.size() - ret;
}
};