simple python solution


  • 0
    X
    class Solution(object):
        def isPowerOfTwo(self, n):
            """
            :type n: int
            :rtype: bool
            """
            n = float(n)
            if n<1:
                return False
            if n == 1:
                return True
            if n>=2:
                while n>=2:
                    n = n/2
                if n == 1:
                    return True
                else:
                    return False
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.