1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-12-15 15:12:35 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
Files
leetcode-problemset/leetcode-cn/problem (English)/最大平衡异或子数组的长度(English) [find-maximum-balanced-xor-subarray-length].html
2025-12-06 16:04:11 +08:00

47 lines
1.6 KiB
HTML

<p>Given an integer array <code>nums</code>, return the <strong>length</strong> of the <strong>longest <span data-keyword="subarray-nonempty">subarray</span></strong> that has a bitwise XOR of zero and contains an <strong>equal</strong> number of <strong>even</strong> and <strong>odd</strong> numbers. If no such subarray exists, return 0.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [3,1,3,2,0]</span></p>
<p><strong>Output:</strong> <span class="example-io">4</span></p>
<p><strong>Explanation:</strong></p>
<p>The subarray <code>[1, 3, 2, 0]</code> has bitwise XOR <code>1 XOR 3 XOR 2 XOR 0 = 0</code> and contains 2 even and 2 odd numbers.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [3,2,8,5,4,14,9,15]</span></p>
<p><strong>Output:</strong> <span class="example-io">8</span></p>
<p><strong>Explanation:</strong></p>
<p>The whole array has bitwise XOR <code>0</code> and contains 4 even and 4 odd numbers.</p>
</div>
<p><strong class="example">Example 3:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [0]</span></p>
<p><strong>Output:</strong> <span class="example-io">0</span></p>
<p><strong>Explanation:</strong></p>
<p>No non-empty subarray satisfies both conditions.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
<li><code>0 &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
</ul>