Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class StockSpanner {
- stack<pair<int, int> > s;
- public:
- StockSpanner() {
- }
- int next(int price) {
- int res = 1;
- while(!s.empty() && s.top().first <= price){
- res += s.top().second;
- s.pop();
- }
- s.push(make_pair(price, res));
- return res;
- }
- };
- /**
- * Your StockSpanner object will be instantiated and called as such:
- * StockSpanner* obj = new StockSpanner();
- * int param_1 = obj->next(price);
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement