Easy CPP Solution
\n\n# Code\ncpp []\nclass Solution {\npublic:\n    long long countAlternatingSubarrays(vector<int>& nums) \n    {\n          long long ans=1;\n          long lo
\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    long long countAlternatingSubarrays(vector<int>& nums) \n    {\n          long long ans=1;\n          long long j=0;\n          for (long long i=1;i<nums.size();i++)\n          {\n            if (nums[i]==nums[i-1]) j=i;\n            ans+=(i-j+1);\n          }\n          return ans;\n    }\n};\n```
['C++']