diff --git a/src/Test191.kt b/src/Test191.kt new file mode 100644 index 0000000..dba7b9c --- /dev/null +++ b/src/Test191.kt @@ -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)) + + } +} \ No newline at end of file