方法1:位运算
时间复杂度:$O(1)$
空间复杂度:$O(1)$
解题思路
结论。
https://leetcode.cn/problems/power-of-two/solution/2de-mi-by-leetcode-solution-rny3/
Java 代码
class Solution {
public boolean isPowerOfTwo(int n) {
return n > 0 && (n & (n - 1)) == 0;
}
}