1839. Decode XORed Array
My accepted Python solution to LeetCode problem 1839, Decode XORed Array, running in 0ms.
- Difficulty: Easy
- Python
- Runtime 0ms
- Memory 19.5MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 0ms, memory 19.5MB, accepted 2025-12-29.
class Solution:
def decode(self, encoded: List[int], first: int) -> List[int]:
# XOR property: if a XOR b = c, then a XOR c = b
# Time: O(n), Space: O(n) for output
arr = [first]
for e in encoded:
arr.append(arr[-1] ^ e)
return arr