[Accepted] Swift
\nclass Solution {\n    func countAlternatingSubarrays(_ nums: [Int]) -> Int {\n\n        var dp = Array(repeating: 1, count: nums.count)\n\n        for i in 1.
```\nclass Solution {\n    func countAlternatingSubarrays(_ nums: [Int]) -> Int {\n\n        var dp = Array(repeating: 1, count: nums.count)\n\n        for i in 1..<nums.count\n            where nums[i] != nums[i - 1] {\n                dp[i] += dp[i - 1]\n            }\n        \n        return dp.reduce(0, +)\n    }\n}\n```
['Swift']