Single Number II

Medium Bit Manipulation

nums is a list of whole numbers.

Every value in nums appears exactly three times, except one value, which appears only once.

Return the value that appears once.

Example 1

Input: nums = [5,-4,5,9,-4,5,-4]
Output: 9

5 and -4 each appear three times, 5 at places 0, 2 and 5 and -4 at places 1, 4 and 6; 9 appears once.

Example 2

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

Example 3

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

Constraints

  • 1 ≤ nums.length < 3 × 10⁵
  • -2³¹ ≤ nums[i] ≤ 2³¹ - 1
  • One value appears exactly once in nums, and every other value exactly three times

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