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 986a34a commit b589fd2Copy full SHA for b589fd2
number-of-1-bits/0-chan.ts
@@ -0,0 +1,10 @@
1
+/**
2
+ * time complexity : O(logn)
3
+ * space complexity : O(logn)
4
+ */
5
+function hammingWeight(n: number): number {
6
+ const MAX_NUM = 2147483648 - 1;
7
+
8
+ const bitwiseOperated = (n & MAX_NUM).toString(2);
9
+ return bitwiseOperated.replaceAll('0', '').length;
10
+};
0 commit comments