leetcode

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

0795.cpp (473B)


      1 class Solution {
      2   public:
      3     int numSubarrayBoundedMax(const vector<int> &nums, int left, int right) const {
      4         int res = 0, good = -1, last = -1;
      5 
      6         for (int i = 0; i < size(nums); i++) {
      7             if (nums[i] < left)
      8                 res += good - last;
      9             else if (nums[i] > right)
     10                 good = last = i;
     11             else {
     12                 res += i - last;
     13                 good = i;
     14             }
     15         }
     16 
     17         return res;
     18     }
     19 };