How about using Java binary literals (0x55 == 0b0101_0101)?


  • 0
    T

    Same as always:

    return (num & (num - 1)) == 0 && (num & 0x55555555) != 0;
    

    but the hex literal can be replaced with 0b01010101_01010101_01010101_01010101 since Java 7.
    I think it shows the intention more than the hex literal.


Log in to reply
 

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