[C++] trick of number of subarray
Approach 1: trick of number of subarray [1]\nTime/Space Complexity: O(N); O(1)\n\nclass Solution {\npublic:\n  int numSubarrayBoundedMax(vector<int>& A, int L, 
Approach 1: trick of number of subarray [1]\nTime/Space Complexity: O(N); O(1)\n```\nclass Solution {\npublic:\n  int numSubarrayBoundedMax(vector<int>& A, int L, int R) {\n    return count(A, R) - count(A, L - 1);\n  }\nprivate:\n  // Count # of sub arrays whose max element is <= N\n  int count(const vector<int>& A, int N) {\n    int ans = 0;\n    int cur = 0;\n    for (int a: A) {\n      if (a <= N)  // continue grow sub arrays\n        ans += ++cur; // small trick, refer [1]\n      else // reset the starting of sub array\n        cur = 0;\n    }\n    return ans;\n  }\n};\n```\n\nApproach 2: compact version of Approach 1\n```\nclass Solution {\npublic:\n  int numSubarrayBoundedMax(vector<int>& A, int L, int R) {\n    return count(A, R) - count(A, L - 1);\n  }\n\nprivate:\n  // Count # of sub arrays whose max element is <= N\n  int count(const vector<int>& A, int N) {\n    int ans = 0;\n    int cur = 0;\n    for (int a: A) \n        a <= N ? ans += ++cur : cur = 0;\n    return ans;\n  }\n};\n```\n\nReference:\n[1] https://leetcode.com/problems/count-substrings-with-only-one-distinct-letter/discuss/1268334/c-sum-equation-of-arithmetic-sequence\n[2] https://leetcode.com/problems/number-of-subarrays-with-bounded-maximum/solution/
['C']