Skip to content

Commit 1865969

Browse files
authored
Merge pull request AlgoMaster-io#3 from htadg/main
🩹 fixed java > counting bits > Approach 3
2 parents 6af5f77 + 0383e89 commit 1865969

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

java/counting-bits.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ public int[] countBits(int n) {
8181
for (int i = 1; i <= n; i++) {
8282
if (i == pow) {
8383
pow *= 2; // Move to the next power of two
84-
x = 1;
84+
x = i;
8585
}
86-
res[i] = res[x++] + 1; // Use the result from a smaller index plus one
86+
res[i] = res[i-x] + 1; // Use the result from a smaller index plus one
8787
}
8888
return res;
8989
}

0 commit comments

Comments
 (0)