diff --git a/Pull Here/LeetCode/CountingBits/countingBits.cpp b/Pull Here/LeetCode/CountingBits/countingBits.cpp new file mode 100644 index 0000000..23b4d9e --- /dev/null +++ b/Pull Here/LeetCode/CountingBits/countingBits.cpp @@ -0,0 +1,11 @@ +class Solution { +public: + vector countBits(int n) { + vector dp(n + 1); + dp[0] = 0; + for (int i = 1; i <= n; i++) { + dp[i] = dp[i >> 1] + (i & 1); + } + return dp; + } +};