Class Solution
- java.lang.Object
-
- g2601_2700.s2683_neighboring_bitwise_xor.Solution
-
public class Solution extends Object
2683 - Neighboring Bitwise XOR.Medium
A 0-indexed array
derived
with lengthn
is derived by computing the bitwise XOR (\u2295) of adjacent values in a binary arrayoriginal
of lengthn
.Specifically, for each index
i
in the range[0, n - 1]
:- If
i = n - 1
, thenderived[i] = original[i] \u2295 original[0]
. - Otherwise,
derived[i] = original[i] \u2295 original[i + 1]
.
Given an array
derived
, your task is to determine whether there exists a valid binary arrayoriginal
that could have formedderived
.Return true if such an array exists or false otherwise.
- A binary array is an array containing only 0’s and 1’s
Example 1:
Input: derived = [1,1,0]
Output: true
Explanation: A valid original array that gives derived is [0,1,0].
derived[0] = original[0] \u2295 original[1] = 0 \u2295 1 = 1
derived[1] = original[1] \u2295 original[2] = 1 \u2295 0 = 1
derived[2] = original[2] \u2295 original[0] = 0 \u2295 0 = 0
Example 2:
Input: derived = [1,1]
Output: true
Explanation: A valid original array that gives derived is [0,1].
derived[0] = original[0] \u2295 original[1] = 1
derived[1] = original[1] \u2295 original[0] = 1
Example 3:
Input: derived = [1,0]
Output: false
Explanation: There is no valid original array that gives derived.
Constraints:
n == derived.length
1 <= n <= 105
- The values in
derived
are either 0’s or 1’s
- If
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
doesValidArrayExist(int[] derived)
-