leetcode

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

3101.cpp (304B)


      1 class Solution {
      2   public:
      3     long long countAlternatingSubarrays(const vector<int> &nums) const {
      4         long long res = 1;
      5 
      6         for (int i = 1, cnt = 1; i < size(nums); i++) {
      7             cnt = nums[i] == nums[i - 1] ? 1 : cnt + 1;
      8             res += cnt;
      9         }
     10 
     11         return res;
     12     }
     13 };