[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;
}

}

posted @ 2021-06-06 23:48  ACBingo  阅读(23)  评论(0编辑  收藏  举报