1314. 2的幂
给定一个整数,写一个函数来确定它是否是2的幂。
样例
样例
输入: n = 3
输出: false
public class Solution {
/**
* @param n: an integer
* @return: if n is a power of two
*/
public boolean isPowerOfTwo(int n) {
// Write your code here
if(n <= 0) return false;
return (n & (n - 1)) == 0;
}
}