题目 Given an integer, write a function to determine if it is a power of two. 解题思路 如果一个数n不为0,那么这个数是2的幂与n & (n - 1) = 0为充要条件 代码 class Solution: def isPowerOfTwo(self, n: int) -> bool: return n and not (n & (n - 1)) 视频讲解 YouTube<--欢迎点击订阅 视频讲解 bilibili<--欢迎点击订阅 Previous LeetCode 518 Coin Change 2 (Python) Next LeetCode 392 Is Subsequence (With Follow up) (Python)