0908
This commit is contained in:
parent
bd07ab1e88
commit
cbb6ca1dc4
1 changed files with 20 additions and 0 deletions
20
src/Test191.kt
Normal file
20
src/Test191.kt
Normal 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))
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue