C++ 1 line code


  • 2
    W

    return (((unsigned)1 << (32 - __builtin_clz(num))) - 1) ^ num;

    using g++ built in function to count the number of leading zeros.


Log in to reply
 

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