1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/交替子数组计数 [count-alternating-subarrays].html
2024-04-07 13:02:43 +08:00

43 lines
1.5 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个<span data-keyword="binary-array">二进制数组 </span><code>nums</code></p>
<p>如果一个<span data-keyword="subarray-nonempty">子数组</span><strong>不存在 </strong>两个 <strong>相邻 </strong>元素的值 <strong>相同</strong> 的情况,我们称这样的子数组为 <strong>交替子数组 </strong></p>
<p>返回数组 <code>nums</code> 中交替子数组的数量。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">nums = [0,1,1,1]</span></p>
<p><strong>输出:</strong> <span class="example-io">5</span></p>
<p><strong>解释:</strong></p>
<!-- 解释示例1的交替子数组 -->
<p>以下子数组是交替子数组:<code>[0]</code><code>[1]</code><code>[1]</code><code>[1]</code> 以及 <code>[0,1]</code></p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">nums = [1,0,1,0]</span></p>
<p><strong>输出:</strong> <span class="example-io">10</span></p>
<p><strong>解释:</strong></p>
<!-- 解释示例2的交替子数组 -->
<p>数组的每个子数组都是交替子数组。可以统计在内的子数组共有 10 个。</p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
<li><code>nums[i]</code> 不是 <code>0</code> 就是 <code>1</code></li>
</ul>