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)/解码异或后的排列 [decode-xored-permutation].html

31 lines
1.0 KiB
HTML
Raw Normal View History

2022-03-27 20:45:09 +08:00
<p>给你一个整数数组 <code>perm</code> ,它是前 <code>n</code> 个正整数的排列,且 <code>n</code> 是个 <strong>奇数</strong> 。</p>
<p>它被加密成另一个长度为 <code>n - 1</code> 的整数数组 <code>encoded</code> ,满足 <code>encoded[i] = perm[i] XOR perm[i + 1]</code> 。比方说,如果 <code>perm = [1,3,2]</code> ,那么 <code>encoded = [2,1]</code> 。</p>
<p>给你 <code>encoded</code> 数组,请你返回原始数组 <code>perm</code> 。题目保证答案存在且唯一。</p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre><b>输入:</b>encoded = [3,1]
<b>输出:</b>[1,2,3]
<b>解释:</b>如果 perm = [1,2,3] ,那么 encoded = [1 XOR 2,2 XOR 3] = [3,1]
</pre>
<p><strong>示例 2</strong></p>
<pre><b>输入:</b>encoded = [6,5,4,6]
<b>输出:</b>[2,4,1,5,3]
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>3 &lt;= n &lt; 10<sup>5</sup></code></li>
<li><code>n</code> 是奇数。</li>
<li><code>encoded.length == n - 1</code></li>
</ul>