# 231. Power of two

`Input: n = 1Output: trueExplanation: 20 = 1`
`Input: n = 16Output: trueExplanation: 24 = 16`
`Input: n = 3Output: false`
• `-231 <= n <= 231 - 1`
`class Solution:    def isPowerOfTwo(self, n: int) -> bool:        if(n<0):            return False        cnt=0        while(n):            if(n&1==1):                cnt+=1            n>>=1        if(cnt==1):            return True         return False`
`class Solution:    def isPowerOfTwo(self, n: int) -> bool:        i=1        while(i<n):            i*=2        return(i==n)`
`class Solution: def isPowerOfTwo(self, n: int) -> bool:  return(False if n<=0 else math.log2(n).is_integer())`

--

--

## More from Dhanarajappu

Tech-Enthusiast, Coder,Explorer,Geeky,Software Engineer |A piece of code delivers everything that you need. The world is all about codes.

Love podcasts or audiobooks? Learn on the go with our new app.

## Dhanarajappu

12 Followers

Tech-Enthusiast, Coder,Explorer,Geeky,Software Engineer |A piece of code delivers everything that you need. The world is all about codes.