Java 4ms Tricky way


  • -1
    Z

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

    Simply use bitcount to count bit :0


Log in to reply
 

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