4ms C solution without loop/recursion,using Bit operation


  • 0
    K
    bool isPowerOfFour(int num) {
        if ((num&1==1 && 1!=num) || num<0)
            return false;
        if (
           num==1
        || num == 4
        || num == 4<<2
        || num == 4<<4
        || num == 4<<6
        || num == 4<<8
        || num == 4<<10
        || num == 4<<12
        || num == 4<<14
        || num == 4<<16
        || num == 4<<18
        || num == 4<<20
        || num == 4<<22
        || num == 4<<24
        || num == 4<<26
        || num == 4<<28
        )
            return true;
        else
            return false;
    }
    

Log in to reply
 

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