Beats 100% | Easy Java Solution | ✅✅✅✅
Please Upvote \u2705\u2705\n\n# Code\n\nclass Solution {\n    public long countAlternatingSubarrays(int[] nums) {\n        long ans = 1;\n        int count = 0;
# Please Upvote \u2705\u2705\n\n# Code\n```\nclass Solution {\n    public long countAlternatingSubarrays(int[] nums) {\n        long ans = 1;\n        int count = 0;\n        \n        for(int i=1;i<nums.length;i++){\n            ans++;\n            if(nums[i]+nums[i-1] == 1) {\n                ans+=(i-count);\n            }\n            else count=i;\n        }\n        return ans;\n    }\n}\n```
['Math', 'Counting', 'Java']