We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7272fde commit ae4a8daCopy full SHA for ae4a8da
counting-bits/heozeop.cpp
@@ -0,0 +1,31 @@
1
+// Time Complexity: O(n^2)
2
+// Spatial Complexity: O(n)
3
+
4
+class Solution {
5
+private:
6
+ int count1(int n) {
7
+ int ans = 0;
8
9
+ while(n) {
10
+ if (n % 2) {
11
+ ++ans;
12
+ }
13
14
+ n /= 2;
15
16
17
+ return ans;
18
19
20
+public:
21
+ vector<int> countBits(int n) {
22
+ vector<int> ans(n + 1);
23
24
+ for(int i = 0; i <= n; ++i) {
25
+ ans[i] = this->count1(i);
26
27
28
29
30
+};
31
0 commit comments