Share my Solution with Explanations


  • 0
    C
     public static boolean isPowerOfFour(int num) {
    	// num & (num - 1) indicates that num is power of 2
    	// (num & 0x55555555) != 0 means that num is power of 4;
    	return num > 0 && (num & (num - 1)) == 0 && (num & 0x55555555) != 0;
      }

Log in to reply
 

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