Skip to content

Commit ec54f9b

Browse files
authored
Create yeongu.cpp
1 parent a74616d commit ec54f9b

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

number-of-1-bits/yeongu.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(int n) {
4+
int cnt = 0;
5+
while(n>0){
6+
int val = n%2;
7+
cnt+=val;
8+
n/=2;
9+
}
10+
return cnt;
11+
}
12+
};

0 commit comments

Comments
 (0)