mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-10-12 17:05:15 +08:00
update
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
<p>You are given an integer array <code>nums</code> of length <code>n</code> where each element is a non-negative integer.</p>
|
||||
|
||||
<p>Select <strong>two</strong> <span data-keyword="subsequence-array">subsequences</span> of <code>nums</code> (they may be empty and are <strong>allowed</strong> to <strong>overlap</strong>), each preserving the original order of elements, and let:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>X</code> be the bitwise XOR of all elements in the first subsequence.</li>
|
||||
<li><code>Y</code> be the bitwise XOR of all elements in the second subsequence.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return the <strong>maximum</strong> possible value of <code>X XOR Y</code>.</p>
|
||||
|
||||
<p><strong>Note:</strong> The XOR of an <strong>empty</strong> subsequence is 0.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,3]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">3</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>Choose subsequences:</p>
|
||||
|
||||
<ul>
|
||||
<li>First subsequence <code>[2]</code>, whose XOR is 2.</li>
|
||||
<li>Second subsequence <code>[2,3]</code>, whose XOR is 1.</li>
|
||||
</ul>
|
||||
|
||||
<p>Then, XOR of both subsequences = <code>2 XOR 1 = 3</code>.</p>
|
||||
|
||||
<p>This is the maximum XOR value achievable from any two subsequences.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [5,2]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">7</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>Choose subsequences:</p>
|
||||
|
||||
<ul>
|
||||
<li>First subsequence <code>[5]</code>, whose XOR is 5.</li>
|
||||
<li>Second subsequence <code>[2]</code>, whose XOR is 2.</li>
|
||||
</ul>
|
||||
|
||||
<p>Then, XOR of both subsequences = <code>5 XOR 2 = 7</code>.</p>
|
||||
|
||||
<p>This is the maximum XOR value achievable from any two subsequences.</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= nums.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>0 <= nums[i] <= 10<sup>9</sup></code></li>
|
||||
</ul>
|
Reference in New Issue
Block a user