Created
November 14, 2016 07:11
-
-
Save ABcDexter/dc4aa81863372d50caf980677e79cc6e to your computer and use it in GitHub Desktop.
Check whether a given positive integer N is power of 2 or not in log(N) complexity.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def isPow2(num): | |
rem=num%2 | |
while num>1: | |
if rem==1: | |
return False | |
rem=num%2 | |
num/=2 | |
if num>1: | |
return False | |
else: | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment