342. Power of Four

Posted optor

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了342. Power of Four相关的知识,希望对你有一定的参考价值。

原题链接:https://leetcode.com/problems/power-of-four/description/
这道题目我没想出实现来,看得讨论区别人的答案:

/**
 * Created by clearbug on 2018/2/26.
 */
public class Solution {

    public static void main(String[] args) {
        Solution s = new Solution();
        System.out.println(s.isPowerOfFour(5));
        System.out.println(s.isPowerOfFour(8));
        System.out.println(s.isPowerOfFour(16));
    }

    public boolean isPowerOfFour(int num) {
        return num > 0 && (num & (num - 1)) == 0 && (num & 0x55555555) != 0;
    }

}

以上是关于342. Power of Four的主要内容,如果未能解决你的问题,请参考以下文章

342. Power of Four

342. Power of Four

342 Power of Four 4的幂

[leetcode] 342. Power of Four

342. Power of Four(LeetCode)

LeetCode 342. Power of Four