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 4eeebf3 commit c4397beCopy full SHA for c4397be
number-of-1-bits/tolluset.ts
@@ -0,0 +1,10 @@
1
+/*
2
+ * TC: O(logn)
3
+ * SC: O(logn)
4
+ * */
5
+function hammingWeight(n: number): number {
6
+ return n
7
+ .toString(2)
8
+ .split("")
9
+ .filter((s) => s === "1").length;
10
+}
0 commit comments