美文网首页
03_3的幂

03_3的幂

作者: butters001 | 来源:发表于2019-11-04 10:31 被阅读0次
# 使用了循环 不符合要求
class Solution(object):
    def isPowerOfThree(self, n):
        """
        :type n: int
        :rtype: bool
        """
        while True:
            if n % 3 == 0:
                if n == 3:
                    return True
                n /= 3
            else:
                return False


class Solution2(object):
    def isPowerOfThree(self, n):
        """
        :type n: int
        :rtype: bool
        """
        return n > 0 and 3 ** 19 % n == 0


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




n = 27
s = Solution()
print(s.isPowerOfThree(n))

相关文章

  • 03_3的幂

  • 杨幂

    甜甜的大幂幂 寻寻幂幂,不离不弃

  • 【2期】她们不告别娱乐圈,就没幂幂诗诗爽爽什么事了

    幂幂镇楼。 说到幂幂,(我,幂幂死忠粉)感觉幂幂的人气下降得厉害。最直接的是,去年前年大前年杨幂生日,一线二线三线...

  • 介绍一下,这是我女神。

    我喜欢北京,因为幂幂出生在北京 我喜欢浅色,因为幂幂是白浅 我喜欢下雪天,因为幂幂是雪见 她是我们所有粉丝的骄傲 ...

  • 2018-10-21

    知识点1:幂的运算 (1)同底数幂的乘法法则: 同底数幂相乘,底数不变,指数相加 (2)幂的乘方法则: 幂的乘方,...

  • [娱乐]明日之子,各人设分析

    最近一直在追《明日之子》很简单,是我最爱的大幂幂的综艺。(只要是大幂幂的综艺我都不会错过) 所以我只是看幂幂的美颜...

  • 快速幂

    常规求幂 快速求幂(一般) 快速求幂 (递归) 快速求幂(位运算) 快速求幂(位运算,更简洁)

  • 这也能掰?杨幂是要被恋爱多少次?

    自从杨幂和刘恺威官宣离婚之后,杨幂的感情生活就没平静过,网友们对杨幂是真爱啊,想要大幂幂尽快找到新的幸福。 杨幂和...

  • Q版人物全身画

    临摹大幂幂

  • 2017-07-07

    最爱大幂幂

网友评论

      本文标题:03_3的幂

      本文链接:https://www.haomeiwen.com/subject/ayvrbctx.html