//给定一个整数,编写一个函数来判断它是否是 2 的幂次方。 
//
// 示例 1: 
//
// 输入: 1
//输出: true
//解释: 20 = 1 
//
// 示例 2: 
//
// 输入: 16
//输出: true
//解释: 24 = 16 
//
// 示例 3: 
//
// 输入: 218
//输出: false 
// Related Topics 位运算 数学 
// 👍 290 👎 0

/*
* 231 2的幂
* 2021-03-12 14:05:09
* @author oxygenbytes
*/ 
#include "leetcode.h" 
//leetcode submit region begin(Prohibit modification and deletion)
class Solution2 {
public:
    bool isPowerOfTwo(int n) {
        return n > 0 && (1 << 30) % n == 0;
    }
};

class Solution{
public:
    bool isPowerOfTwo(int n){
        return n > 0 & (n & -n) == n;
    }
};
//leetcode submit region end(Prohibit modification and deletion)