Single Number III

Medium Bit Manipulation

nums is a list of whole numbers.

Two values in nums appear only once each, and every other value appears exactly twice.

Return the two values that appear once, in either order.

Example 1

Input: nums = [7,-2,9,7,4,9]
Output: [-2,4]

7 and 9 appear twice each, so -2 and 4 are the two that appear once; [4, -2] is right too.

Example 2

Input: nums = [0,6]
Output: [0,6]

Example 3

Input: nums = [-5,8,-5,8,11,-13]
Output: [-13,11]

Constraints

  • 2 ≤ nums.length ≤ 3 × 10⁵
  • -2³¹ ≤ nums[i] ≤ 2³¹ - 1
  • Exactly two values appear once in nums, and every other value exactly twice

Practice this in an AI round

30 minutes on this problem with an AI agent beside your code, then a report on your solution and how you used the agent.

See the AI round

Watch the explanation

More Bit Manipulation

All Bit Manipulation problems