Skip to content

Commit

Permalink
Merge pull request #1683 from vardaan-raj/master
Browse files Browse the repository at this point in the history
Create CheckPowerOf2.py
  • Loading branch information
fineanmol committed Oct 1, 2022
2 parents f9f46a7 + baddc37 commit 3d14ddf
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#Question : Given an integer n, return true if it is a power of two. Otherwise, return false.
#An integer n is a power of two, if there exists an integer x such that n == 2x.

def isPowerOfTwo(self, n: int) -> bool:
if n<0:
return False
if str(bin(n)).count('1')==1:
return True
return False

0 comments on commit 3d14ddf

Please sign in to comment.