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