Python3 solution with two pointers
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\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```python3 []\n"""\nTwo pointers\nnums = [1,0,1,0]\nexp: 10\n 1 + (1 + 1) + (1 + 1 + 1) + (1 + 1 + 1 +) = 1 + 2 + 3 + 4 = 10\n"""\n\nclass Solution:\n    def countAlternatingSubarrays(self, nums: List[int]) -> int:\n        """T: O(N)"""\n\n        ans = 0\n        left = 0\n\n        for right in range(len(nums)):\n            \n            if nums[right] == nums[right - 1]:\n                left = right\n\n            ans += (right - left + 1)\n\n        return ans\n\n    def countAlternatingSubarrays1(self, nums: List[int]) -> int:\n        """T: O(N^2)"""\n        ans = 0\n\n        for i in range(len(nums)):\n            for j in range(i, len(nums)):\n                if i == j:\n                    ans += 1\n\n                else:\n                    if nums[j] != nums[j - 1]:\n                        ans += 1\n                    else:\n                        break\n\n        return ans\n```
['Python3']