Find the Single Number

Published by Deep Xavier in

Write a function that accepts an array of numbers (where each number appears three times except for one which appears only once) and finds that unique number in the array and returns it.

Examples

singleNumber([2, 2, 3, 2]) ➞ 3

singleNumber([0, 1, 0, 1, 0, 1, 99]) ➞ 99

singleNumber([-1, 2, -4, 20, -1, 2, -4, -4, 2, -1]) ➞ 20

Notes

The function needs to be efficient in order to run under 12,000 milliseconds.

Watch a quick demo on how Edabit works.