Java 2 lines-easy to understand solution

  • 0

    Use bitset class. if a number is power of 4, only one bit should be set and that too at odd position bit(take few examples). This is the intuitive idea behind.

     BitSet bs = BitSet.valueOf(new long[]{num});
    		return ( num>0 && bs.nextSetBit(0)%2==0 && (num & (num-1))==0)==true;

Log in to reply

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