Description
Given an array where every element appears three times except one, find that single one. Use bit manipulation for O(1) space.
Examples
Input:
nums = [2,2,3,2]Output:
3Explanation:
3 appears once, 2 appears three times.
Input:
nums = [5,7,5,4,7,4,4,5,7]Output:
4Explanation:
In this array, 5 appears three times and 7 appears three times, but 4 appears only once. Therefore, 4 is the single number that doesn't follow the pattern of appearing three times.
Input:
nums = [-1]Output:
-1Explanation:
This is a minimal case where the array contains only one element. Since there's only one number and it doesn't appear three times, -1 is the single number is being looking for.
Constraints
- •
1 ≤ nums.length ≤ 3 * 10⁴ - •
-2³¹ ≤ nums[i] ≤ 2³¹ - 1