Skip to content

Commit 9c1aff7

Browse files
authored
Merge pull request #867 from pontusdacke/191-number-of-1-bits
Add csharp solution for 191 number of 1 bits
2 parents c3c15f7 + f2b372d commit 9c1aff7

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Diff for: csharp/191-Number-Of-1-Bits.cs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
public class Solution {
2+
public int HammingWeight(uint n) {
3+
var binary = Convert.ToString(n, 2);
4+
var hammingWeight = 0;
5+
for (int i = 0; i < binary.Length; i++)
6+
{
7+
hammingWeight += binary[i] - '0';
8+
}
9+
return hammingWeight;
10+
}
11+
}

0 commit comments

Comments
 (0)