【leetcode❤python】326. Power of Three

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

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