1 2 3 4 5 6 7 8 9 10 11 12 13 14
| class Solution { public: int numSubarrayBoundedMax(vector<int>& nums, int left, int right) { function<int(int)> count = [&](int lower) { int res = 0, cnt = 0; for (int num : nums) { cnt = num <= lower ? cnt + 1 : 0; res += cnt; } return res; }; return count(right) - count(left - 1); } };
|