Skip to content

Commit dd6e5b5

Browse files
committed
Number Of 1 Bits 🦚️
1 parent 271957c commit dd6e5b5

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

number of 1 bits.cpp

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

0 commit comments

Comments
 (0)