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 1703022 commit 17686d4Copy full SHA for 17686d4
Day28.cpp
@@ -0,0 +1,29 @@
1
+/*
2
+ Author: Aryan Yadav
3
+ Counting Bits
4
+ Complexity: O(n)
5
+ Difficulty: Medium
6
+*/
7
+
8
+class Solution {
9
+public:
10
+ vector<int> countBits(int num) {
11
+ vector<int> v(num+1);
12
+ for(int i=0;i<=num;i++){
13
+ v[i] = v[i>>1] + (i & 1);
14
+ }
15
+ return v;
16
17
+};
18
19
+/* Easy Solution */
20
21
22
23
24
25
+ v[i] = __builtin_popcount(i);
26
27
28
29
0 commit comments