Power of Two

https://www.lintcode.com/problem/power-of-two/description

public class Solution {
    /**
     * @param n: an integer
     * @return: if n is a power of two
     */
    public boolean isPowerOfTwo(int n) {
        // Write your code here
        while (n > 1) {
            if ((n & 1) == 1) {
                return false;
            }
            n >>>= 1;
        }
        return true;
    }
}

你可能感兴趣的:(Power of Two)