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 b971000 commit 8cea40dCopy full SHA for 8cea40d
191. Number of 1 Bits
@@ -0,0 +1,27 @@
1
+class Solution {
2
+public:
3
+ int hammingWeight(uint32_t n) {
4
+ int count =0;
5
+
6
+ //****Approach 1****
7
+ // while( n!= 0){
8
+ // count += (n%2); // Remainder Count... easy Binary count
9
+ // n >>=1;
10
+ // }
11
+ // return count;
12
13
+ //*****Approach 2*****
14
+ // while(n>0){
15
+ // n = (n&(n-1)); // Bit Manipulation
16
+ // count++;
17
18
19
20
+ //*****Approach 3*****
21
+ while(n !=0){
22
+ count += (n%2); //Remainder Count... easy Binary count
23
+ n = n/2;
24
+ }
25
+ return count;
26
27
+};
0 commit comments