Open Tcdian opened 4 years ago
/**
* @param {number} n
* @return {boolean}
*/
var isPowerOfTwo = function(n) {
if (n <= 0) {
return false;
}
return (n & (n - 1)) === 0;
};
function isPowerOfTwo(n: number): boolean {
if (n <= 0) {
return false;
}
return (n & (n - 1)) === 0;
};
231. Power of Two
给定一个整数,编写一个函数来判断它是否是
2
的幂次方。Example 1
Example 2
Example 3