Find the one element that appears exactly once when every other element appears twice.
Given an integer array nums, every element appears exactly twice except for one element which appears only once.
Return the element that appears once.
You should aim for a solution with linear time complexity and constant extra space.
nums1 <= nums.lengthnumsExample 1
Input
nums = [2,2,1]
Output
1
Explanation
All numbers appear twice except 1, so the answer is 1.
Example 2
Input
nums = [4,1,2,1,2]
Output
4
Explanation
1 and 2 each appear twice, leaving 4 as the unique value.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.