Bitwise XOR of All Array Elements
easySave
ArrayBit Manipulation
Given an array of integers, compute the bitwise XOR of all elements in the array.
Example 1
Input
[ 1, 2, 3 ]
Output
0
Explanation. The bitwise XOR of 1, 2, and 3 is 0 (since 1 XOR 2 XOR 3 = 0).
Example 2
Input
[ 4, 5, 6, 7 ]
Output
2
Explanation. The bitwise XOR of 4, 5, 6, and 7 is 2 (since 4 XOR 5 XOR 6 XOR 7 = 2).
Example 3
Input
[ 8 ]
Output
8
Explanation. The bitwise XOR of a single element array is the element itself.
Follow-up: Can you solve this in linear time and constant space complexity?
Constraints:
1. The array will contain at least one element.\n2. All integers in the array will be non-negative.
- Views
- 2