LeetCode · Math & Bits

Math & Bit Manipulation Problem Set

XOR tricks, bit counting, matrix rotation, and integer arithmetic. These problems test mathematical insight more than data structure knowledge.

DifficultyPatternProblemKey Insight
EasyXORLC 136 · Single NumberXOR all elements. Duplicates cancel out. O(n).
Easybit-countLC 191 · Number of 1 Bitsn & (n-1) clears lowest set bit. Count iterations. O(32).
EasyreverseLC 190 · Reverse BitsExtract LSB, shift into result. 32 iterations. O(1).
EasymathLC 268 · Missing NumberXOR [0..n] with array, or use sum formula. O(n).
EasyDP+bitsLC 338 · Counting Bitsdp[i] = dp[i >> 1] + (i & 1). O(n).
MediummathLC 7 · Reverse IntegerPop digits with mod/div, check overflow before push. O(log n).
MediummatrixLC 48 · Rotate ImageTranspose + reverse each row. In-place. O(n²).
MediummatrixLC 73 · Set Matrix ZeroesUse first row/col as markers. O(1) extra space. O(m·n).
Mediumbit-opsLC 371 · Sum of Two IntegersXOR for sum without carry, AND + shift for carry. Repeat until no carry. O(32).

← Back to all LeetCode categories