Skip to main content
Medium Bit Manipulation Medium frequency

Single Number II

Open on LeetCode

Approach Summary

Sum bits at each position modulo 3. The bit that does not cancel is the unique number's bit. Use two variables (ones, twos) for a clean state machine.

How to Recognize This Pattern

  • Every element appears 3× except one
  • Bit-count mod 3 at each position — 32 separate counters or state machine

Complexity Analysis

Time Complexity

O(n)

Space Complexity

O(1)

Tags

Array Bit Manipulation

This site is free. If these guides are helping your prep, consider buying me a coffee. ☕

Support →
Buy me a coffee