LeetCode solutions

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

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 0ms, memory 19.5MB, accepted 2025-12-29.

python
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

Source