文巾解题 326. 3的幂

Posted UQI-LIUWJ

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了文巾解题 326. 3的幂相关的知识,希望对你有一定的参考价值。

1 题目描述

2 解题思路

2.1 循环递归

class Solution:
    def isPowerOfThree(self, n: int) -> bool:
        if(n<=0):
            return False
        while(n%3==0):
            n=n//3
        return(n==1)

 2.2  3^20的约数

思路和文巾解题 231. 2的幂_UQI-LIUWJ的博客-CSDN博客 2.5 一致

class Solution:
    def isPowerOfThree(self, n: int) -> bool:
        if(n<=0):
            return False
        max_3=math.pow(3,20)
        if(max_3 % n==0):
            return True
        return False

以上是关于文巾解题 326. 3的幂的主要内容,如果未能解决你的问题,请参考以下文章

LeetCode 326 3的幂[数学 循环] HERODING的LeetCode之路

leetcode326.三的幂(342.四的幂/231.二的幂)

leetcode刷题笔记326 3的幂

Leetcode 326.3的幂 By Python

326-3的幂

LeetCode刷题326-简单-3的幂