Java/Python Clean Solution
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
# 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 {\n    public long countAlternatingSubarrays(int[] nums) {\n        long count =0;\n        int left = 0;\n        for(int right = 0; right<nums.length; right++){\n            if(right>0 && nums[right]==nums[right-1]){\n                left = right;\n            }\n            count += right-left+1;\n        }\n        return count;\n    }\n}\n```\n```\nclass Solution:\n    def countAlternatingSubarrays(self, nums: List[int]) -> int:\n        count = 0\n        left = 0\n        for right in range(len(nums)):\n            if right>0 and nums[right] == nums[right-1]:\n                left = right\n            \n            count += right-left +1\n        return count\n```
['Array', 'Two Pointers', 'Python', 'Java', 'Python3']