Simple python3 solution | 766 ms - faster than 100.00% solutions
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# Co
# 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``` python3 []\nclass Solution:\n    def countAlternatingSubarrays(self, nums: List[int]) -> int:\n        result = 0\n        prev = None\n        length = 0\n        for elem in nums:\n            if elem == prev:\n                length = 1\n            else:\n                length += 1\n            result += length\n            prev = elem\n        return result\n```
['Math', 'Greedy', 'Counting', 'Python3']