C++ Solution || Easy to Understand
Code\ncpp []\nclass Solution {\npublic:\n    long long countAlternatingSubarrays(vector<int>& nums) {\n        if (nums.size() == 1) return 1;\n        long lon
# Code\n```cpp []\nclass Solution {\npublic:\n    long long countAlternatingSubarrays(vector<int>& nums) {\n        if (nums.size() == 1) return 1;\n        long long count = nums.size();\n        long long len =0;\n        for (long long i = 1; i < nums.size(); i++) {\n            if (nums[i] != nums[i - 1]) {\n                len++;;\n            } else {\n                count+= (len)*(len+1)/2;\n                len=0;\n            }if(i==nums.size()-1) count+=(len)*(len+1)/2;\n        }\n        return count;\n    }\n};\n\n```
['C++']