每日一题力扣326 啊这

给定一个整数,写一个函数来判断它是否是 3 的幂次方。如果是,返回 true ;否则,返回 false 。

整数 n 是 3 的幂次方需满足:存在整数 x 使得 n == 3x

来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/power-of-three
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。

class Solution:
    def isPowerOfThree(self, n: int) -> bool:
        while n>=3:
            n/=3
        return n==1
原文地址:https://www.cnblogs.com/liuxiangyan/p/14510945.html