This commit is contained in:
kagura 2024-09-10 11:12:16 +08:00
parent bd07ab1e88
commit cbb6ca1dc4

20
src/Test191.kt Normal file
View file

@ -0,0 +1,20 @@
class Test191 {
class Solution {
fun hammingWeight(n: Int): Int {
var result = 0
var num = n
while (num != 0){
result += num%2
num = num.shr(1)
}
return result
}
}
fun test(){
println(Solution().hammingWeight(11))
println(Solution().hammingWeight(128))
println(Solution().hammingWeight(2147483645))
}
}