Single Number II
Given an integer array nums where every element appears three times except for one element that appears exactly once, return the element that appears only once.
You must solve the problem in linear runtime complexity and use constant extra space.
Example 1
Input
n = 4 nums = [2, 2, 2, 3]
Output
3
Explanation
2 appears three times, while 3 appears only once.
Example 2
Input
n = 7 nums = [0, 1, 0, 1, 0, 1, 99]
Output
99
Explanation
0 and 1 each appear three times, while 99 appears only once.
Constraints
Hints:
Hint 1
Consider each bit position independently.
Hint 2
For every bit, count how many numbers have that bit set.
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