Python: one for() loop
\n# Complexity\nBeats 100% (time)\n\n\n\n# Code\npython []\nclass Solution(object):\n\n    def countAlternatingSubarrays(self, nums):\n        """\n        :typ
\n# Complexity\nBeats 100% (time)\n\n\n\n# Code\n```python []\nclass Solution(object):\n\n    def countAlternatingSubarrays(self, nums):\n        """\n        :type nums: List[int]\n        :rtype: int\n        """\n        count = 0\n        alt_length = 1\n        for i in range(1, len(nums)):\n            if nums[i]!=nums[i-1]:\n                alt_length+=1\n            else:\n                count+=(alt_length*(alt_length+1)/2)\n                alt_length = 1\n        count+=(alt_length*(alt_length+1)/2)\n        return count\n```
['Python']