15% off all plans & roadmaps Use code
See plansLeetCode 137 · Solution & editorial
Given an integer array nums where every element appears three times except for one, which appears exactly once. Find the single element and return it.
Single Number II is a Bit Manipulation Patterns problem, in the Bitwise XOR - Finding Single/Missing Number subpattern. The pattern covers XOR tricks, counting bits, power-of-two checks, and Hamming weight
Use XOR properties to find single number, missing number, and duplicates.
The reference solution runs in O(n) time and O(1) space.
Single Number II has been reported in interviews at Google, Adobe.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Single Number II is a Bit Manipulation Patterns problem, in the Bitwise XOR - Finding Single/Missing Number subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.