首页 > 技术文章 > LeetCode "Power of Two"

tonix 2015-07-06 07:35 原文

Just one line. Bit-wise ops:

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

推荐阅读