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 3475a97 commit b2ce37eCopy full SHA for b2ce37e
number-of-1-bits/eunice-hong.ts
@@ -0,0 +1,7 @@
1
+function hammingWeight(n: number): number {
2
+ // 1. convert the number to a binary string
3
+ const binaryString = n.toString(2);
4
+
5
+ // 2. count the number of 1s in the binary string
6
+ return binaryString.split("").filter((char) => char === "1").length;
7
+}
0 commit comments