Can anybody tell me why this solution fails on the case 536870912(2^29)?


  • 0
    G

    The solution is:

        bool isPowerOfTwo(int n) {
            return log(n)/log(2)==(int)(log(n)/log(2));
        }
    

    It passes all other cases except 2^29 this one. It is not the result of overflow, since it generates correct answer on 2^30. Is it something like inline type transformation?
    It is quite weired!


Log in to reply
 

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