Search⌘ K
AI Features

Solution: Single Number II

Explore how to apply bitwise XOR operations to identify the two unique elements in an array where every other element appears twice. Understand how to partition the array using the rightmost set bit to isolate the unique numbers efficiently in O(n) time and constant space.

Statement

Given a non-empty array arr, in which exactly two elements appear once, and all the other elements appear twice, return the two elements that appeared only once.

Note: The result can be returned in any order. The solution should use only constant extra space.

Constraints:

  • 22 \leq ...