Math Fundamentals18 sections · 814 units
Open in Course

Problem - Single Number

LeetCode 136

Given a non-empty array of integers nums, every element appears twice except for one. Find that single one. You must implement a solution with O(1)O(1) extra space.

Example: nums = [2,2,1] returns 11. Example: nums = [4,1,2,1,2] returns 44.

This problem uses XOR, the exclusive OR operator you learned earlier. Think about XOR's properties before reading the solution.