Saturday, November 25, 2017

231. Power of Two

class Solution:
    def isPowerOfTwo(self, n):
        """
        :type n: int
        :rtype: bool
        """
        if bin(n)[2] == "1" and bin(n)[3:] == (len(bin(n))-3) * "0":
            return True
        else:
            return False

No comments:

Post a Comment