A few problems

This commit is contained in:
2022-05-29 20:21:38 +01:00
parent 2c0204028e
commit 2a7ec7e34b
17 changed files with 228 additions and 1 deletions

12
number-of-1-bits/sol.rs Normal file
View File

@@ -0,0 +1,12 @@
impl Solution {
pub fn hammingWeight (n: u32) -> i32 {
(0..32).into_iter()
.fold(0, |acc, p| {
let compare_bit = 1 << p;
if n & compare_bit == compare_bit {
return acc + 1;
}
acc
})
}
}