【leetcode❤python】231. Power of Two

#-*- coding: UTF-8 -*-
class Solution(object):
    def isPowerOfTwo(self, n):
        if(n<=0):
            return False
        if(n==1):
            return True
        while True:
            tuple=divmod(n,2)
            if tuple[1]!=0:
                return False
            if tuple[0]==1:
                return True
            n=tuple[0]
        
sol=Solution()
print sol.isPowerOfTwo(1025)

posted @ 2016-10-12 17:00  火金队长  阅读(163)  评论(0编辑  收藏  举报