1284. Find the Only Non-Repeating Element (XOR)

EasyBit ManipulationBit ManipulationXORArray

Given an array where every element appears an even number of times except exactly one element that appears an odd number of times, return that single element. XOR-ing all elements cancels the paired ones and leaves the answer.

Input: A JSON object {"nums": [<integers>]} with exactly one odd-count element.

Output: Return the element that appears an odd number of times.

Examples

Example 1
Input: {"nums":[4,1,2,1,2]}
Output: 4
Explanation: The 1s and 2s cancel, leaving 4.
Example 2
Input: {"nums":[7]}
Output: 7
Explanation: A lone element is the answer -> 7.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →