Python | DP | Easy to understand
\nclass Solution:\n    def countAlternatingSubarrays(self, nums: List[int]) -> int:\n        n = len(nums)\n        dp = [1] * n\n        \n        for i in ran
```\nclass Solution:\n    def countAlternatingSubarrays(self, nums: List[int]) -> int:\n        n = len(nums)\n        dp = [1] * n\n        \n        for i in range(1, n):\n            if nums[i-1] != nums[i]:\n                dp[i] = dp[i - 1] + 1\n        \n        return sum(dp)\n```
['Dynamic Programming', 'Python3']