Problem of the Day
A Fresh Challenge, Every Day
One new problem every day — try to solve it yourself before checking the solution.
Easy
Single Number
Given a non-empty array of integers nums, every element appears twice except for one. Find that single one.
Constraints
- The array
numswill always contain exactly one element that appears only once. - Your algorithm should have a linear runtime complexity.
- Can you implement it without using extra memory (i.e., constant space complexity)?
Examples
Example 1:
Input: nums = [2,2,1]
Output: 1
Example 2:
Input: nums = [4,1,2,1,2]
Output: 4
