Math Fundamentals18 sections · 814 units
Open in Course

Problem - Single Number

LeetCode 136

You're given an array where every element appears twice except for one. Find that single element.

For example, [4,1,2,1,2][4, 1, 2, 1, 2] returns 44. The constraint: solve it in O(n)O(n) time and O(1)O(1) space.

Think about XOR's properties. What happens when you XOR all the numbers together?