[LeetCode] 231. 2 的幂

位运算

231. 2 的幂

``` class Solution { public boolean isPowerOfTwo(int n) { int cnt = 0;
    while (n>0) {
        if ((n & 1) == 1) cnt++;
        n >>= 1;
    }

    return cnt == 1;
}

}

原文地址:https://www.cnblogs.com/acbingo/p/14856923.html