标签:
题目:
Given an integer (signed 32 bits), write a function to check whether it is a power of 4.
Example:
Given num = 16, return true. Given num = 5, return false.
Follow up: Could you solve it without loops/recursion?
1 public class Solution { 2 public boolean isPowerOfFour(int num) { 3 if(num<=0) 4 return false; 5 int a=0x2aaaaaaa; 6 if(((num&a)==0)&&((num&(num-1))==0)) 7 { 8 return true; 9 } 10 return false; 11 } 12 }
标签:
原文地址:http://www.cnblogs.com/HelloWorld-5/p/5413508.html