FastPrepFind the Unique Element Among Pairs

Find the Unique Element Among Pairs

Chubb logoChubb● EasyNEW GRADPHONE SCREEN
Learn

Problem statement

You are given a nonempty integer array nums. Exactly one value appears once and every other value appears exactly twice.

Return the value that appears once. The input is not necessarily sorted.

Function

singleNumber(nums: int[]) → int

Examples

Example 1

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

The values 1 and 2 form pairs, leaving 4.

Example 2

nums = [-7,3,3]return = -7

The two 3 values cancel as a pair.

Constraints

  • 1 <= nums.length <= 200001.
  • nums.length is odd.
  • -1000000000 <= nums[i] <= 1000000000.
  • Exactly one value appears once; every other value appears twice.

More Chubb problems

See Chubb hiring insights
public int singleNumber(int[] nums) {
    // Write your solution here.
}
nums[4,1,2,1,2]
expected4
Checking account…