Single Number Finder
Given a non-empty array of integers where every element appears twice except for one, find that single one. We need to find the element that appears only once in the array while all other elements appear twice.
[ 4, 1, 2, 1, 2 ]
Explanation. In this array, the number 4 is the only number that appears exactly once.
[ 2, 2, 1 ]
Explanation. The number 1 appears only once, while 2 appears twice.
[ 7, 5, 5, 6, 6 ]
Explanation. Every number except 7 has a duplicate in the array.
Follow-up: Can you implement a solution with a linear runtime complexity and without using extra memory?
- You may assume that the input always has exactly one number that appears exactly once.\n- All other numbers in the input will appear exactly twice.\n- The input array will never be empty.
- Views
- 2