Lone Value Among Triples
A replicated store writes every record to three nodes, so every value in nums appears exactly three times, except one value that appears only once.
Return that value using O(1) extra memory.
Example 1
Input: nums = [2, 2, 3, 2] Output: 3
Example 2
Input: nums = [0, 1, 0, 1, 0, 1, 99] Output: 99
Constraints
- 1 <= nums.length <= 3 * 10^4 + 1
- -2^31 <= nums[i] <= 2^31 - 1
Hint 1
Count how many numbers have each of the 32 bits set; the lone value has the bits whose count is not a multiple of 3.
Hint 2
Two bit masks can track counts modulo 3 for every bit at once.
Discussion 0
Join free to post in the discussion.
Good practice for: Embedded Systems Engineer, Game Developer, Backend Developer, Blockchain Developer, Automation Test Engineer
Run checks your code on 2 sample tests. Submit runs all 7 tests, including hidden ones, and earns points. Use console.log to debug. Python's first run can take a few seconds while it starts.