Simple C++ Solution || Counting || Easy To Understand
\n# Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(1)\n Add your space complexity here, e.g. O(n) \n\n#
\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    long long countAlternatingSubarrays(vector<int>& nums) {\n        int n=nums.size();\n        long long res=1;\n        long long check=0,curr=1;\n        for(int i=1;i<n;i++){\n            if(nums[i] != nums[i-1]){\n                curr++;\n                res += curr;\n            }\n            else{\n                curr=1;\n                res += curr;\n            }\n        }\n        return res;\n    }\n};\n```
['Sliding Window', 'Counting', 'C++']