Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    2433 - Find The Original Array of Prefix Xor\.

    Medium

    You are given an integer array pref of size n. Find and return the array arr of size n that satisfies:

    • pref[i] = arr[0] ^ arr[1] ^ ... ^ arr[i].

    Note that ^ denotes the bitwise-xor operation.

    It can be proven that the answer is unique.

    Example 1:

    Input: pref = 5,2,0,3,1

    Output: 5,7,2,3,2

    Explanation: From the array 5,7,2,3,2 we have the following:

    • pref0 = 5.

    • pref1 = 5 ^ 7 = 2.

    • pref2 = 5 ^ 7 ^ 2 = 0.

    • pref3 = 5 ^ 7 ^ 2 ^ 3 = 3.

    • pref4 = 5 ^ 7 ^ 2 ^ 3 ^ 2 = 1.

    Example 2:

    Input: pref = 13

    Output: 13

    Explanation: We have pref0 = arr0 = 13.

    Constraints:

    • <code>1 <= pref.length <= 10<sup>5</sup></code>

    • <code>0 <= prefi<= 10<sup>6</sup></code>

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final IntArray findArray(IntArray pref)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait