Beats 100% || Easy Soln - n*(n+1)/2
Intuition\n\n# Approach\n# Complexity\n- Time complexity:\nO(n)\n- Space complexity:\nO(1)\n# Code\n\nclass Solution {\n    public long countAlternatingSubarray
# Intuition\n\n# Approach\n# Complexity\n- Time complexity:\nO(n)\n- Space complexity:\nO(1)\n# Code\n```\nclass Solution {\n    public long countAlternatingSubarrays(int[] nums) {\n        if(nums.length==1)return 1;\n        long ans=0;\n        int i=0,j=0;\n        \n        while(j<nums.length-1){\n            \n            if(nums[j]==nums[j+1]){\n                ans=ans+(long)(j-i+1)*(j-i+2)/2;\n                i=j+1;\n            }\n                j++;\n        }\n        ans=ans+(long)(j-i+1)*(j-i+2)/2;\n        return ans;\n    }\n}\n```
['Math', 'Sliding Window', 'Java']