Given an integer n, please judge whether the integer is a power of 2.Returns true if so; otherwise, returns false .
If there is an integer x such that n == 2x , then n is considered to be a power of 2.
Example 1:
Input: n = 1
Output: true
Explanation: 20 = 1
Example 2:
Input: n = 16
Output: true
Explanation: 24 = 16
If n = 2 x n = 2^x n=2x, must be satisfied, n and (n-1) are equal to 0.
class Solution:def isPowerOfTwo(self, n: int)-> bool:return n>0 and (n&(n-1)==0)