Simple math solution JS || O(n) || O(1)
Approach\n Describe your approach to solving the problem. \n- Declare a variable to count the consecutive number\n- If nums[i] !== nums[i - 1], increase the con
# Approach\n<!-- Describe your approach to solving the problem. -->\n- Declare a variable to count the consecutive number\n- If nums[i] !== nums[i - 1], increase the consecutive by 1\n- Else set consecutive = 1\n- Count will be increased by consecutive for each loop\n\n# 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```\n/**\n * @param {number[]} nums\n * @return {number}\n */\nvar countAlternatingSubarrays = function (nums) {\n    let count = nums.length,\n        continues = 1;\n    for (let i = 1; i < nums.length; i++) {\n        if (nums[i] !== nums[i - 1]) {\n            count += continues;\n            continues++;\n        } else {\n            continues = 1;\n        }\n    }\n\n    return count;\n};\n```
['JavaScript']