Decode XORed Permutation LeetCode solution in Python

1
# Runtime: 1921 ms (Top 32.18%) | Memory: 33.8 MB (Top 16.09%)
2

3
from functools import reduce
4
from operator import xor
5

6

7
class Solution:
8

9
def decode(self, encoded: List[int]) -> List[int]:
10
n = len(encoded) + 1
11
a = reduce(xor, range(1, n + 1))
12
b = reduce(xor, encoded[1::2])
13
result = [a ^ b]
14
for y in encoded:
15
result.append(result[-1] ^ y)
16
return result

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0