mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
46 lines
1.5 KiB
HTML
46 lines
1.5 KiB
HTML
<p>给你一个整数数组 <code>nums</code> 和一个 <strong>正</strong> 整数 <code>k</code> 。</p>
|
||
|
||
<p>定义长度为 <code>2 * x</code> 的序列 <code>seq</code> 的 <strong>值</strong> 为:</p>
|
||
|
||
<ul>
|
||
<li><code>(seq[0] OR seq[1] OR ... OR seq[x - 1]) XOR (seq[x] OR seq[x + 1] OR ... OR seq[2 * x - 1])</code>.</li>
|
||
</ul>
|
||
|
||
<p>请你求出 <code>nums</code> 中所有长度为 <code>2 * k</code> 的 <span data-keyword="subsequence-array">子序列</span> 的 <strong>最大值</strong> 。</p>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong class="example">示例 1:</strong></p>
|
||
|
||
<div class="example-block">
|
||
<p><span class="example-io"><b>输入:</b>nums = [2,6,7], k = 1</span></p>
|
||
|
||
<p><span class="example-io"><b>输出:</b>5</span></p>
|
||
|
||
<p><strong>解释:</strong></p>
|
||
|
||
<p>子序列 <code>[2, 7]</code> 的值最大,为 <code>2 XOR 7 = 5</code> 。</p>
|
||
</div>
|
||
|
||
<p><strong class="example">示例 2:</strong></p>
|
||
|
||
<div class="example-block">
|
||
<p><span class="example-io"><b>输入:</b>nums = [4,2,5,6,7], k = 2</span></p>
|
||
|
||
<p><span class="example-io"><b>输出:</b>2</span></p>
|
||
|
||
<p><strong>解释:</strong></p>
|
||
|
||
<p>子序列 <code>[4, 5, 6, 7]</code> 的值最大,为 <code>(4 OR 5) XOR (6 OR 7) = 2</code> 。</p>
|
||
</div>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ul>
|
||
<li><code>2 <= nums.length <= 400</code></li>
|
||
<li><code>1 <= nums[i] < 2<sup>7</sup></code></li>
|
||
<li><code>1 <= k <= nums.length / 2</code></li>
|
||
</ul>
|