Single Number III

Given an integer array nums where exactly two elements appear once and all the other elements appear twice, return the two elements that appear once. Pattern focus: XOR Trick. XOR everything first, then use a distinguishing bit to split the numbers into two groups.

Input Format

nums = integer array with exactly two unique elements

Output Format

the two unique numbers

Constraints

  • 1 <= input size <= 10^5
  • -10^9 <= numeric values <= 10^9
  • nums must satisfy the format described in inputFormat.

Examples

Example 1:

Input:

nums = [1,2,1,3,2,5]

Output:

[3,5]

Explanation:

The two numbers that appear once are 3 and 5.

Example 2:

Input:

nums = [4,1,2,1,2,5]

Output:

[4,5]

Explanation:

The two unique numbers are 4 and 5.

Loading...
Single Number III - Bit Manipulation DSA Problem