1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/找出前缀异或的原始数组 [find-the-original-array-of-prefix-xor].html
2022-10-15 20:04:57 +08:00

40 lines
1.1 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>给你一个长度为 <code>n</code><strong>整数</strong> 数组 <code>pref</code> 。找出并返回满足下述条件且长度为 <code>n</code> 的数组<em> </em><code>arr</code> </p>
<ul>
<li><code>pref[i] = arr[0] ^ arr[1] ^ ... ^ arr[i]</code>.</li>
</ul>
<p>注意 <code>^</code> 表示 <strong>按位异或</strong>bitwise-xor运算。</p>
<p>可以证明答案是 <strong>唯一</strong> 的。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><strong>输入:</strong>pref = [5,2,0,3,1]
<strong>输出:</strong>[5,7,2,3,2]
<strong>解释:</strong>从数组 [5,7,2,3,2] 可以得到如下结果:
- pref[0] = 5
- pref[1] = 5 ^ 7 = 2
- pref[2] = 5 ^ 7 ^ 2 = 0
- pref[3] = 5 ^ 7 ^ 2 ^ 3 = 3
- pref[4] = 5 ^ 7 ^ 2 ^ 3 ^ 2 = 1
</pre>
<p><strong>示例 2</strong></p>
<pre><strong>输入:</strong>pref = [13]
<strong>输出:</strong>[13]
<strong>解释:</strong>pref[0] = arr[0] = 13
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= pref.length &lt;= 10<sup>5</sup></code></li>
<li><code>0 &lt;= pref[i] &lt;= 10<sup>6</sup></code></li>
</ul>