mycode

class Solution(object):
    def isPowerOfThree(self, n):
        """
        :type n: int
        :rtype: bool
        """
        while n > 2:
            if n%3 != 0 :
                return False
            n = n // 3
            print(n)
        return n == 1

 

参考

class Solution(object):
    def isPowerOfThree(self, n):
        """
        :type n: int
        :rtype: bool
        """
        if n <= 0:
            return False
        while n%3 == 0:
            n = n/3
        return n==1

 

相关文章:

  • 2022-12-23
  • 2021-11-24
  • 2021-12-07
  • 2022-12-23
  • 2021-07-29
  • 2022-12-23
  • 2021-08-23
猜你喜欢
  • 2021-11-29
  • 2021-12-02
  • 2021-09-04
  • 2022-01-29
  • 2021-08-26
  • 2021-08-12
相关资源
相似解决方案