mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
52 lines
2.7 KiB
HTML
52 lines
2.7 KiB
HTML
<p>给你一个整数数组 <code>colors</code> ,它表示一个由红色和蓝色瓷砖组成的环,第 <code>i</code> 块瓷砖的颜色为 <code>colors[i]</code> :</p>
|
||
|
||
<ul>
|
||
<li><code>colors[i] == 0</code> 表示第 <code>i</code> 块瓷砖的颜色是 <strong>红色</strong> 。</li>
|
||
<li><code>colors[i] == 1</code> 表示第 <code>i</code> 块瓷砖的颜色是 <strong>蓝色</strong> 。</li>
|
||
</ul>
|
||
|
||
<p>环中连续 3 块瓷砖的颜色如果是 <strong>交替</strong> 颜色(也就是说中间瓷砖的颜色与它<strong> 左边</strong> 和 <strong>右边</strong> 的颜色都不同),那么它被称为一个 <strong>交替</strong> 组。</p>
|
||
|
||
<p>请你返回 <strong>交替</strong> 组的数目。</p>
|
||
|
||
<p><b>注意</b> ,由于 <code>colors</code> 表示一个 <strong>环</strong> ,<strong>第一块</strong> 瓷砖和 <strong>最后一块</strong> 瓷砖是相邻的。</p>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong class="example">示例 1:</strong></p>
|
||
|
||
<div class="example-block">
|
||
<p><span class="example-io"><b>输入:</b>colors = [1,1,1]</span></p>
|
||
|
||
<p><span class="example-io"><b>输出:</b>0</span></p>
|
||
|
||
<p><strong>解释:</strong></p>
|
||
|
||
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/05/16/image_2024-05-16_23-53-171.png" style="width: 150px; height: 150px; padding: 10px; background: #fff; border-radius: .5rem;" /></p>
|
||
</div>
|
||
|
||
<p><strong class="example">示例 2:</strong></p>
|
||
|
||
<div class="example-block">
|
||
<p><span class="example-io"><b>输入:</b>colors = [0,1,0,0,1]</span></p>
|
||
|
||
<p><b>输出:</b>3</p>
|
||
|
||
<p><b>解释:</b></p>
|
||
|
||
<p><img alt="" src="https://assets.leetcode.com/uploads/2024/05/16/image_2024-05-16_23-47-491.png" style="width: 150px; height: 150px; padding: 10px; background: #fff; border-radius: .5rem;" /></p>
|
||
|
||
<p>交替组包括:</p>
|
||
|
||
<p><strong class="example"><img alt="" src="https://assets.leetcode.com/uploads/2024/05/16/image_2024-05-16_23-50-441.png" style="width: 150px; height: 150px; padding: 10px; background: #fff; border-radius: .5rem;" /></strong><img alt="" src="https://assets.leetcode.com/uploads/2024/05/16/image_2024-05-16_23-48-211.png" style="width: 150px; height: 150px; padding: 10px; background: #fff; border-radius: .5rem;" /><strong class="example"><img alt="" src="https://assets.leetcode.com/uploads/2024/05/16/image_2024-05-16_23-49-351.png" style="width: 150px; height: 150px; padding: 10px; background: #fff; border-radius: .5rem;" /></strong></p>
|
||
</div>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ul>
|
||
<li><code>3 <= colors.length <= 100</code></li>
|
||
<li><code>0 <= colors[i] <= 1</code></li>
|
||
</ul>
|