We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
给定一个整数,编写一个函数来判断它是否是 2 的幂次方。
2
Input: 1 Output: true Explanation: 20 = 1
Input: 16 Output: true Explanation: 24 = 16
Input: 218 Output: false
The text was updated successfully, but these errors were encountered:
/** * @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; };
Sorry, something went wrong.
No branches or pull requests
231. Power of Two
给定一个整数,编写一个函数来判断它是否是
2
的幂次方。Example 1
Example 2
Example 3
The text was updated successfully, but these errors were encountered: