Class Solution
-
- All Implemented Interfaces:
public final class Solution1734 - Decode XORed Permutation\.
Medium
There is an integer array
permthat is a permutation of the firstnpositive integers, wherenis always odd.It was encoded into another integer array
encodedof lengthn - 1, such thatencoded[i] = perm[i] XOR perm[i + 1]. For example, ifperm = [1,3,2], thenencoded = [2,1].Given the
encodedarray, return the original arrayperm. It is guaranteed that the answer exists and is unique.Example 1:
Input: encoded = 3,1
Output: 1,2,3
Explanation: If perm = 1,2,3, then encoded = 1 XOR 2,2 XOR 3 = 3,1
Example 2:
Input: encoded = 6,5,4,6
Output: 2,4,1,5,3
Constraints:
<code>3 <= n < 10<sup>5</sup></code>
nis odd.encoded.length == n - 1
-
-
Constructor Summary
Constructors Constructor Description Solution()
-