1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/查询数组 Xor 美丽值 [find-xor-beauty-of-array].html
2023-01-14 00:20:24 +08:00

51 lines
1.9 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个下标从 <strong>0</strong>&nbsp;开始的整数数组&nbsp;<code>nums</code>&nbsp;</p>
<p>三个下标&nbsp;<code>i</code>&nbsp;<code>j</code>&nbsp;&nbsp;<code>k</code>&nbsp;<strong>有效值</strong>&nbsp;定义为&nbsp;<code>((nums[i] | nums[j]) &amp; nums[k])</code>&nbsp;</p>
<p>一个数组的 <strong>xor 美丽值</strong>&nbsp;是数组中所有满足&nbsp;<code>0 &lt;= i, j, k &lt; n</code>&nbsp;&nbsp;<strong>的三元组</strong>&nbsp;<code>(i, j, k)</code>&nbsp;<strong>有效值</strong>&nbsp;的异或结果。</p>
<p>请你返回&nbsp;<code>nums</code>&nbsp;的 xor 美丽值。</p>
<p><b>注意:</b></p>
<ul>
<li><code>val1 | val2</code>&nbsp;&nbsp;<code>val1</code>&nbsp;<code>val2</code>&nbsp;的按位或。</li>
<li><code>val1 &amp; val2</code>&nbsp;&nbsp;<code>val1</code>&nbsp;<code>val2</code>&nbsp;的按位与。</li>
</ul>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<b>输入:</b>nums = [1,4]
<b>输出:</b>5
<b>解释:</b>
三元组和它们对应的有效值如下:
- (0,0,0) 有效值为 ((1 | 1) &amp; 1) = 1
- (0,0,1) 有效值为 ((1 | 1) &amp; 4) = 0
- (0,1,0) 有效值为 ((1 | 4) &amp; 1) = 1
- (0,1,1) 有效值为 ((1 | 4) &amp; 4) = 4
- (1,0,0) 有效值为 ((4 | 1) &amp; 1) = 1
- (1,0,1) 有效值为 ((4 | 1) &amp; 4) = 4
- (1,1,0) 有效值为 ((4 | 4) &amp; 1) = 0
- (1,1,1) 有效值为 ((4 | 4) &amp; 4) = 4
数组的 xor 美丽值为所有有效值的按位异或 1 ^ 0 ^ 1 ^ 4 ^ 1 ^ 4 ^ 0 ^ 4 = 5 。</pre>
<p><strong>示例 2</strong></p>
<pre>
<b>输入:</b>nums = [15,45,20,2,34,35,5,44,32,30]
<b>输出:</b>34
<code><span style=""><b>解释:</b>数组的 xor 美丽值为</span> 34 。</code>
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length&nbsp;&lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
</ul>