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)/所有数对按位与结果的异或和 [find-xor-sum-of-all-pairs-bitwise-and].html
2022-03-29 12:43:11 +08:00

37 lines
1.6 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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>异或和</strong><strong>XOR sum</strong>)指对所有元素进行按位 <code>XOR</code> 运算的结果。如果列表中仅有一个元素,那么其 <strong>异或和</strong> 就等于该元素。</p>
<ul>
<li>例如,<code>[1,2,3,4]</code><strong>异或和</strong> 等于 <code>1 XOR 2 XOR 3 XOR 4 = 4</code> ,而 <code>[3]</code><strong>异或和</strong> 等于 <code>3</code></li>
</ul>
<p>给你两个下标 <strong>从 0 开始</strong> 计数的数组 <code>arr1</code><code>arr2</code> ,两数组均由非负整数组成。</p>
<p>根据每个 <code>(i, j)</code> 数对,构造一个由 <code>arr1[i] AND arr2[j]</code>(按位 <code>AND</code> 运算)结果组成的列表。其中 <code>0 &lt;= i &lt; arr1.length</code><code>0 &lt;= j &lt; arr2.length</code></p>
<p>返回上述列表的 <strong>异或和</strong></p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre><strong>输入:</strong>arr1 = [1,2,3], arr2 = [6,5]
<strong>输出:</strong>0
<strong>解释:</strong>列表 = [1 AND 6, 1 AND 5, 2 AND 6, 2 AND 5, 3 AND 6, 3 AND 5] = [0,1,2,0,2,1]
异或和 = 0 XOR 1 XOR 2 XOR 0 XOR 2 XOR 1 = 0 。</pre>
<p><strong>示例 2</strong></p>
<pre><strong>输入:</strong>arr1 = [12], arr2 = [4]
<strong>输出:</strong>4
<strong>解释:</strong>列表 = [12 AND 4] = [4] ,异或和 = 4 。
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= arr1.length, arr2.length &lt;= 10<sup>5</sup></code></li>
<li><code>0 &lt;= arr1[i], arr2[j] &lt;= 10<sup>9</sup></code></li>
</ul>