Find the Duplicate Number
Given an array of integers where each number appears exactly twice except for one number which appears once, find the number that appears only once. The solution should have a linear time complexity and use no extra space.
[ 1, 2, 2, 3, 1 ]
Explanation. Here, the number '3' is the only number that appears once.
[ 4, 7, 4, 5, 5 ]
Explanation. In this case, '7' appears only once while all other numbers appear twice.
[ 10, 10, 22 ]
Explanation. Number '22' is the unique number appearing once.
Follow-up: Can this problem be extended to finding unique elements in an array where every element appears `n` times except for one element?
1. The length of the array is always odd.\n2. All integers in the array except one appear exactly twice.
- Views
- 9