88. Single Number

Easy · Bit Manipulation

Given a non-empty array of integers where every element appears exactly twice except for one element which appears exactly once, find and return that single element.

You must implement a solution with O(1) space complexity (not counting the input array).

Examples

Example 1
Input: [2, 2, 1]
Output: 1
Explanation: The element 2 appears twice, and 1 appears once. Return 1.
Example 2
Input: [4, 1, 2, 1, 2]
Output: 4
Explanation: Elements 1 and 2 each appear twice, while 4 appears once. Return 4.

Constraints