Find the Unique Number
Given an array of integers where every number appears twice except for one, find and return the unique number that does not appear twice.
[ 2, 3, 2, 4, 4 ]
Explanation. In the array, every number except for 3 appears twice. Therefore, the output is 3.
[ 7, 7, 6 ]
Explanation. In the array, every number except for 6 appears twice. Thus, 6 is returned.
[ 22, 22, 33, 45, 45 ]
Explanation. 33 is the number appearing only once while all others appear twice.
[ 0, 1, 1 ]
Explanation. 0 is the unique number as all other numbers appear twice.
[ 11, 11, 88, 99, 88, 77, 77 ]
Explanation. 99 is the unique among the numbers, appearing only once.
Follow-up: Can this problem be solved in a more efficient use of space?
The input array should contain at least one element and a maximum of 100 elements. All numbers will be integers.
- Views
- 1