leetcode326

public class Solution {
    public bool IsPowerOfThree(int n) {
        return n > 0 && (1162261467 % n == 0);
    }
}

https://leetcode.com/problems/power-of-three/#/description

使用循环实现,python

1 class Solution:
2     def isPowerOfThree(self, n: int) -> bool:
3         while n > 2 and n %3 == 0:
4             n = n // 3
5         return n == 1
原文地址:https://www.cnblogs.com/asenyang/p/6732621.html