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)


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