#3101

Count Alternating Subarrays

medium · 57.3% accepted · 242 likes · top 53%

array · math

Description

You are given a binary array nums.

We call a subarray alternating if no two adjacent elements in the subarray have the same value.

Return the number of alternating subarrays in nums.

Solution