LeetCode 191: Number of 1 Bits and How to Skip Irrelevant Zeros

Problem Requirement Given a positive integer n, return the number of 1 bits in its binary representation. This count is also called the Hamming weight. LeetCode provides this method contract: hammingWeight(n: int) -> int Example 1 Input: n = 11 Binary: 1011 Output: 3 Example 2 Input: n = 128 Binary: 10000000 Output: 1 Constraints 1 <= n <= 2^31 - 1 The input stays in the problem’s non-negative integer domain. Although the current constraints start at 1, the implementation also handles n = 0 naturally and returns 0. ...

July 15, 2026 · 5 min · map[name:Jeanphilo]

LeetCode 338: Counting Bits by Reusing Smaller Results

Problem Requirement Given a non-negative integer n, return an array answer of length n + 1. For every index: answer[i] = the number of 1 bits in the binary representation of i The requested range includes both 0 and n. LeetCode provides this method contract: countBits(n: int) -> List[int] Example 1 Input: n = 2 Output: [0,1,1] 0 -> 0 -> 0 set bits 1 -> 1 -> 1 set bit 2 -> 10 -> 1 set bit Example 2 Input: n = 5 Output: [0,1,1,2,1,2] Constraints 0 <= n <= 10^5 Step 1: This Time We Need Every Answer From 0 to n LeetCode 191 asks for one integer’s set-bit count. For n = 5, this problem asks for all six related answers: ...

July 15, 2026 · 5 min · map[name:Jeanphilo]

LeetCode 231: Power of Two (Bit Trick O(1) ACERS Guide)

Subtitle / Summary A classic bit-manipulation template: determine if a number is a power of two in O(1). This ACERS guide covers the core insight, practical uses, and runnable multi-language implementations. Reading time: 8–12 min Tags: bit manipulation, binary, math SEO keywords: Power of Two, bit manipulation, binary, O(1), LeetCode 231 Meta description: O(1) power-of-two check using bit tricks, with engineering scenarios and multi-language code. A — Algorithm Problem Restatement Given an integer n, determine whether it is a power of two. Return true if it is; otherwise, return false. ...

January 21, 2026 · 6 min · map[name:Jeanphilo]