Simple Python 39ms 97th%


  • 0
    V
    class Solution(object):
        def isPowerOfTwo(self, n):
            """
            :type n: int
            :rtype: bool
            """
            if n == 0:
                return False
            if n == 1:
                return True
            
            while n % 2 == 0:
                if n == 2:
                    return True
                n /= 2
            
            return False
    

Log in to reply
 

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