simple | easy java solution
Complexity\n- Time complexity:\nlinear time complexity O(n)\n\n- Space complexity:\nconstant space complexity O(1)\n\n# Code\n\nclass Solution {\n    public lon
# Complexity\n- Time complexity:\nlinear time complexity O(n)\n\n- Space complexity:\nconstant space complexity O(1)\n\n# Code\n```\nclass Solution {\n    public long countAlternatingSubarrays(int[] nums) {\n        long count = 1;\n        int start = 0; \n        int end = 0;\n\n        for (int i = 1; i < nums.length; i++) {\n            end++;\n            if (nums[i] == nums[i - 1]) {\n                start = end;\n            }\n            \n            count += end - start + 1;\n        }\n\n        return count;\n    }\n}\n```
['Two Pointers', 'Sliding Window', 'Java']