✅ Java Solution | Easy to understand
CODE\nJava []\npublic long countAlternatingSubarrays(int[] nums) {\n\tlong res = 0l;\n\tint n = nums.length;\n\tint i=0, j=1;\n\twhile(j < n){\n\t\tif(nums[j] =
## **CODE**\n```Java []\npublic long countAlternatingSubarrays(int[] nums) {\n\tlong res = 0l;\n\tint n = nums.length;\n\tint i=0, j=1;\n\twhile(j < n){\n\t\tif(nums[j] == nums[j-1]) {\n\t\t\ti = j;\n\t\t} else {\n\t\t\tres += (j-i);\n\t\t}\n\t\tj++;\n\t}\n\treturn res+n;\n}\n```
['Java']