Sliding window , C++
Intuition\nuse sliding window approach\n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time complexity:\n Add your time compl
# Intuition\nuse sliding window approach\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\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        long long ans=1,left=0;\n        for(int i=1;i<nums.size();i++){\n             if(nums[i]==nums[i-1])left=i;\n             ans+=(i-left+1);\n        }\n        return ans;\n    }\n};\n```
['C++']