Advertisement
kai-rocket

Decode XORed Array

Mar 26th, 2021
445
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None
  1. class Solution:
  2.     def decode(self, encoded: List[int], first: int) -> List[int]:
  3.         # Initialise arr with first
  4.         arr = [first] * (len(encoded) + 1)
  5.    
  6.         # Loop through encoded
  7.         # Use encoded[0] and first to generate arr[1]
  8.         # Use encoded[1] and arr[1] to generate arr[2]
  9.         # ...
  10.         for i in range(len(encoded)):
  11.             # Put next_arr_num in i+1th index in arr
  12.             arr[i+1] = encoded[i] ^ arr[i]
  13.            
  14.         # Return arr
  15.         return arr
  16.            
  17.        
Advertisement
RAW Paste Data Copied
Advertisement