Python 3 || 7 lines, simple count  || T/S: 98% / 93%
\nclass Solution:\n    def countAlternatingSubarrays(self, nums: List[int]) -> int:\n\n        ans, curr =  0, nums[0]\n\n        for num in nums:\n            
```\nclass Solution:\n    def countAlternatingSubarrays(self, nums: List[int]) -> int:\n\n        ans, curr =  0, nums[0]\n\n        for num in nums:\n            prev, curr = curr, num\n \n            if prev^curr == 0: cnt = 0\n\n            cnt+= 1\n\n            ans+= cnt\n            \n        return ans\n```\n[https://leetcode.com/problems/count-alternating-subarrays/submissions/1219322345/](https://leetcode.com/problems/count-alternating-subarrays/submissions/1219322345/)\n\n\n\nI could be wrong, but I think that time complexity is *O*(*N*) and space complexity is *O*(1), in which *N* ~ `len(nums)`.
['Python3']