Skip to content

Commit

Permalink
Create 338 - Counting Bits.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
animshamura authored Dec 4, 2023
1 parent 6aada25 commit 0791b60
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions 338 - Counting Bits.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Solution {
public:
vector<int> countBits(int n) {
vector<int> ans(n + 1);
for (int i = 1; i <= n; ++i)
ans[i] = ans[i / 2] + (i & 1);
return ans;
}
};

0 comments on commit 0791b60

Please sign in to comment.