Single Number
Given a non-empty integer array nums, every element appears twice except for one element that appears exactly once.
Return the element that appears only once.
You must solve the problem with linear runtime complexity and use constant extra space.
Example 1
Input
n = 3 nums = [2, 2, 1]
Output
1
Explanation
2 appears twice, while 1 appears only once.
Example 2
Input
n = 5 nums = [4, 1, 2, 1, 2]
Output
4
Explanation
1 and 2 each appear twice, while 4 appears only once.
Constraints
Hints:
Hint 1
A value XORed with itself becomes 0.
x ^ x = 0
Hint 2
XOR with 0 leaves the number unchanged.
x ^ 0 = x
Author & Technical Reviewer
Technically reviewed by: ExamAdda Technical Review Team
Technical Reviewers, ExamAdda
Software engineers at ExamAdda who check every article's definitions, complexity claims and code examples before and after publishing.
Published
Aug 23, 2026
Last updated
Aug 23, 2026
Content Verification Methodology
Definitions and complexity claims were checked against authoritative computer-science references. Code examples were compiled and tested with standard, boundary and edge-case inputs.
Expected Output