All problems

Single Number II

Medium · bit manipulation

A library scans the barcodes of returned books. Every barcode is an integer, and every barcode was scanned exactly three times, except for one barcode that was scanned only once.

Given the list nums of scanned barcodes (in no particular order), return the barcode that appears exactly once.

Examples

Example 1

Input: nums = [5, 5, 8, 5]

Output: 8

The barcode 5 was scanned three times and 8 only once.

Example 2

Input: nums = [3, 7, 3, 7, 3, 7, 11]

Output: 11

3 and 7 each appear three times, so 11 is the odd one out.

Example 3

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

Output: -9

Constraints