Given an integer array nums where every element appears three times except for one, which appears exactly once. Find the single element and return it. You must implement a solution with a linear runtime complexity and use only constant extra space.
Example 1
Input: nums = [2,2,3,2]
Output: 3
Explanation: 2 appears three times and 3 appears once.
Example 2
Input: nums = [0,1,0,1,0,1,99]
Output: 99
Explanation: 0 and 1 each appear three times, and 99 appears once.
Example 3
Input: nums = [1]
Output: 1
Explanation: The only element appears once.
Track two bit-masks, `ones` and `twos`, that record which bits have been seen once and twice (mod 3). Each number updates them so that any bit reaching a third occurrence resets to zero. After the pass, `ones` holds the unique number's bits.
Run checks all cases above. Submit evaluates all test cases.