Skip to content

Commit b4dc837

Browse files
committed
✨ [338] dp solution
1 parent bd4b893 commit b4dc837

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

338/o_solution.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @param {number} n
3+
* @return {number[]}
4+
*/
5+
const countBits = (n) => {
6+
let dp = [0], bit = 1;
7+
for (let i = 1; i < n + 1; i++) {
8+
if (i === bit * 2) bit = i;
9+
dp[i] = (1 + dp[i - bit]);
10+
}
11+
12+
console.log("dp")
13+
console.log(dp)
14+
15+
return dp;
16+
}
17+
18+
countBits(5)

0 commit comments

Comments
 (0)