Skip to content

Commit f000c0f

Browse files
committed
number of 1 Bits solution
1 parent 244fe7c commit f000c0f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

number-of-1-bits/PDKhan.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public:
3+
int hammingWeight(int n) {
4+
int cnt = 0;
5+
6+
while(n){
7+
if(n & 1 == 1)
8+
cnt++;
9+
10+
n >>= 1;
11+
}
12+
13+
return cnt;
14+
}
15+
};

0 commit comments

Comments
 (0)