Decode XORed Array - LeetCode

There is a hidden integer array arr that consists of n non-negative integers.

It was encoded into another integer array encoded of length n - 1, such that encoded[i] = arr[i] XOR arr[i + 1]. For example, if arr = [1,0,2,1], then encoded = [1,2,3].

You are given the encoded array. You are also given an integer first, that is the first element of arr, i.e. arr[0].

Return the original array arr. It can be proved that the answer exists and is unique.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/6763f91b-d318-4ab8-9a63-54f95284ceb9/Screen_Shot_2021-04-06_at_12.10.16_PM.png

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/8f1929ee-759a-47dc-97c5-4db81a769110/Untitled.png

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/b157558a-2342-4090-8e7a-1df61db542e3/Untitled.png

[ 4, 2, 0, 7, 4 ] → [ 6, 2, 7, 3 ]

                            [ 4 XOR 2, 2 XOR 0, 0 XOR 7, 7 XOR 4 ]

4, 2

AND: 0, OR: 4(더 큰 수), XOR: