首页 > 代码库 > leetcode_231 Power Of Two(Bit Manipulation)

leetcode_231 Power Of Two(Bit Manipulation)

Given an integer, write a function to determine if it is a power of two.

public class Solution {
    public boolean isPowerOfTwo(int n) {
        return ((n&(n-1))==0&&n>0);
    }
}

强大的位运算!!!

leetcode_231 Power Of Two(Bit Manipulation)