Cheat Answer #1linecode #2ms

  • 0

    Although the answers mentioned are correct. I think this static function of Integer class would help.

    public static int hammingWeight(int n) {
    	return Integer.bitCount(n);

    The performance of this function is not great, but still passes the test cases and would like to share it with others.

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.