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 5651493 commit 0ded189Copy full SHA for 0ded189
1 file changed
number-of-1-bits/DaleSeo.rs
@@ -0,0 +1,13 @@
1
+// TC: O(k)
2
+// SC: O(1)
3
+impl Solution {
4
+ pub fn hamming_weight(n: i32) -> i32 {
5
+ let mut n = n as u32;
6
+ let mut cnt = 0;
7
+ while n != 0 {
8
+ n &= n - 1;
9
+ cnt += 1;
10
+ }
11
+ cnt
12
13
+}
0 commit comments