From 1e30b3c1c1b224213f929326e562cdd0be52af16 Mon Sep 17 00:00:00 2001 From: Christina Fan Date: Sun, 8 Feb 2026 20:57:01 -0800 Subject: [PATCH] fix starting index of hamming weights dp solution --- java/Bit Manipulation/HammingWeightsOfIntegersDp.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/Bit Manipulation/HammingWeightsOfIntegersDp.java b/java/Bit Manipulation/HammingWeightsOfIntegersDp.java index 63793d7..d6b6c8a 100644 --- a/java/Bit Manipulation/HammingWeightsOfIntegersDp.java +++ b/java/Bit Manipulation/HammingWeightsOfIntegersDp.java @@ -3,7 +3,7 @@ public int[] hammingWeightsOfIntegersDp(int n) { // Base case: the number of set bits in 0 is just 0. We set dp[0] to // 0 by initializing the entire DP array to 0. int[] dp = new int[n + 1]; - for (int x = 0; x < n + 1; x++) { + for (int x = 1; x < n + 1; x++) { // 'dp[x]' is obtained using the result of 'dp[x >> 1]', plus // the LSB of 'x'. dp[x] = dp[x >> 1] + (x & 1);