function isPowerOfTwo(n):
if n <= 0:
return false
while n > 1:
if n % 2 != 0:
return false
n = n / 2
return true
Math Fundamentals18 sections · 814 units
Open in CoursePower of Two - Implementation
(15 lines)