C++ Solution beats 100% during contest 31-03-2024
Intuition\n\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Tim
# Intuition\n![Screenshot 2024-03-31 094643.png](https://assets.leetcode.com/users/images/f075734d-6206-4a45-b77b-26bcd180e071_1711858643.6288419.png)\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    long long countAlternatingSubarrays(vector<int>& nums) {\n        int n = nums.size();\n        long long r = 0;\n        int l = 1;\n        for(int i = 1; i < n; i++){\n            if(nums[i] != nums[i - 1])\n                l += 1;\n            else{\n                r += (long long)l * (l + 1) / 2;\n                l = 1;\n            }\n        }\n        r += (long long)l * (l + 1) / 2;\n        return r;\n    }\n};\n```
['C++']