Skip to content

Instantly share code, notes, and snippets.

@thekhairul
Last active May 3, 2022 11:58
Show Gist options
  • Save thekhairul/996a3e7ef97a1ad420113a41703660bc to your computer and use it in GitHub Desktop.
Save thekhairul/996a3e7ef97a1ad420113a41703660bc to your computer and use it in GitHub Desktop.
Leetcode 231: Power of Two - python3
def isPowerOfTwo(n):
left = 0
right = 31
result = False
while left <= right:
mid = (left + right) // 2
if pow(2, mid) == n:
result = True
break
if pow(2, mid) < n:
left = mid + 1
else:
right = mid - 1
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment