WORLD 8
BITS AND MATH
Treat a number as a row of switches: cancel pairs with XOR, clear bits one at a time.
STAGE 0 Bits and math tutorial
0:00 / 0:00
The move
Treat every number as a row of switches. XOR cancels pairs (x ^ x = 0), x & (x - 1) clears the lowest set bit, and shifts double or halve. Math tricks like sums and repeated squaring replace whole loops.
- Spot it
- Every number appears twice except one, count the 1 bits, power of two, no extra space, or a huge exponent.
- Cost
- Each bit operation is one step on a fixed-width number, so one pass is O(n) time and O(1) space.
15 STAGES Bits and math problems
☆☆☆☆☆ Clear 5 to finish this world.
EASY1:38Single Number
Bit manipulationLC 136▶ START
EASY1:42Number of 1 Bits
Bit manipulationLC 191▶ START
EASY1:37Counting Bits
BitsLC 338▶ START
MEDIUM1:37Rotate Image
MatrixLC 48▶ START
MEDIUM1:40Spiral Matrix
MatrixLC 54▶ START
EASY1:43Missing Number
MathLC 268▶ START
MEDIUM1:40Pow(x, n)
Fast exponentiationLC 50▶ START
EASY1:36Reverse Bits
BitsLC 190▶ START
MEDIUM1:45Sum of Two Integers
Bit manipulationLC 371▶ START
MEDIUM1:47Reverse Integer
MathLC 7▶ START
EASY1:42Palindrome Number
MathLC 9▶ START
EASY1:47Happy Number
Fast and slow pointersLC 202▶ START
EASY1:36Plus One
CarryLC 66▶ START
MEDIUM1:48Multiply Strings
CarryLC 43▶ START
MEDIUM1:39Bitwise AND of Numbers Range
Bit manipulationLC 201▶ START