_3101

package
v0.0.0-...-5ea41ec Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 12, 2025 License: MIT Imports: 1 Imported by: 0

README

交替子数组计数

给你一个二进制数组 nums

如果一个子数组中 **不存在 **两个 **相邻 **元素的值 相同 的情况,我们称这样的子数组为 **交替子数组 **。

返回数组 nums 中交替子数组的数量。

示例 1:

**输入:**nums = [0,1,1,1]

**输出:**5

解释:

以下子数组是交替子数组:[0][1][1][1] 以及 [0,1]

示例 2:

**输入:**nums = [1,0,1,0]

**输出:**10

解释:

数组的每个子数组都是交替子数组。可以统计在内的子数组共有 10 个。

提示:

  • 1 <= nums.length <= 105
  • nums[i] 不是 0 就是 1

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL