leetcode 342. Power of Four

题目:

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 }

 

posted @ 2016-04-20 17:08  HelloWorld_5  阅读(188)  评论(0编辑  收藏  举报