mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-10-12 17:05:15 +08:00
34 lines
1.0 KiB
HTML
34 lines
1.0 KiB
HTML
<p>给定一个二进制数组 <code>nums</code> , 找到含有相同数量的 <code>0</code> 和 <code>1</code> 的最长连续子数组,并返回该子数组的长度。</p>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>示例 1:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>nums = [0,1]
|
||
<strong>输出:</strong>2
|
||
<strong>说明:</strong>[0, 1] 是具有相同数量 0 和 1 的最长连续子数组。</pre>
|
||
|
||
<p><strong>示例 2:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>nums = [0,1,0]
|
||
<strong>输出:</strong>2
|
||
<strong>说明:</strong>[0, 1] (或 [1, 0]) 是具有相同数量 0 和 1 的最长连续子数组。</pre>
|
||
|
||
<p><strong>示例 3:</strong></p>
|
||
|
||
<pre>
|
||
<b>输入:</b>nums = [0,1,1,1,1,1,0,0,0]
|
||
<b>输出:</b>6
|
||
<b>解释:</b>[1,1,1,0,0,0] 是具有相同数量 0 和 1 的最长连续子数组。</pre>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ul>
|
||
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||
<li><code>nums[i]</code> 不是 <code>0</code> 就是 <code>1</code></li>
|
||
</ul>
|