Super Easy C++ Solution | 4 lines codes
Code\n\nclass Solution {\npublic:\n    long long countAlternatingSubarrays(vector<int>& nums) {\n        if(nums.size() == 1) return 1;\n        int i = 0, j = 
# Code\n```\nclass Solution {\npublic:\n    long long countAlternatingSubarrays(vector<int>& nums) {\n        if(nums.size() == 1) return 1;\n        int i = 0, j = 0;\n        long long count = 0;\n        while(j < nums.size() ) {\n            count += (j-i+1);\n            if(j < nums.size() - 1 && nums[j] == nums[j+1]) i = j+1;\n            j++;\n        }\n        return count;\n    }\n};\n```
['C++']