leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0901.cpp (473B)


0 class StockSpanner {
1 static const int length = 10001;
2 int size = 0;
3 pair<int, int> stocks[length];
5 public:
6 StockSpanner() {}
8 int next(int price) {
9 int index = size - 1;
10 while (index >= 0)
11 if (price >= stocks[index].first)
12 index -= stocks[index].second;
13 else
14 break;
15 int span = size - index;
16 stocks[size++] = make_pair(price, span);
17 return span;
18 }
19 };