LeetCode 231. 2的幂

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

这里引用评论区Kico大神的解释。

 

posted @ 2020-10-31 17:20  peanut_zh  阅读(46)  评论(0编辑  收藏  举报