Loading problem...
You are given a non-empty array of integers called nums, where every element appears exactly twice except for one element that appears only once. Your task is to identify and return the element that appears just once.
The challenge requires you to design a solution that achieves:
This constraint eliminates straightforward approaches like using hash maps or sorting, pushing you to think about more elegant bit manipulation techniques.
nums = [2,2,1]1In this array, the element 2 appears twice at indices 0 and 1, while the element 1 appears only once at index 2. Therefore, 1 is the unique element that we should return.
nums = [4,1,2,1,2]4The element 1 appears at indices 1 and 3, the element 2 appears at indices 2 and 4, but the element 4 appears only once at index 0. Hence, 4 is the unique element.
nums = [1]1The array contains only a single element, which by definition must be the unique one. Since there are no duplicates, we simply return 1.
Constraints