Skip to content

Commit 08efb30

Browse files
committed
Add May Day 19
1 parent a200178 commit 08efb30

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class StockSpanner {
2+
public:
3+
stack<pair<int, int>> stocks;
4+
int dayCount;
5+
StockSpanner() {
6+
dayCount = 0;
7+
}
8+
9+
int next(int price) {
10+
int n = stocks.size();
11+
while (!stocks.empty() && stocks.top().second <= price)
12+
stocks.pop();
13+
dayCount++;
14+
int span = (stocks.empty()) ? (dayCount) : (dayCount - stocks.top().first);
15+
stocks.push(make_pair(dayCount, price));
16+
return span;
17+
}
18+
};
19+
20+
/**
21+
* Your StockSpanner object will be instantiated and called as such:
22+
* StockSpanner* obj = new StockSpanner();
23+
* int param_1 = obj->next(price);
24+
*/

0 commit comments

Comments
 (0)