v1
- 递归法
class Solution:
def isPowerOfThree(self, n: int) -> bool:
return n > 0 and 1162261467 % n == 0
v2
- -231 <= n <= 231 - 1 此范围内3的幂最大为3**19为116226146,故可用n>0,且1162261467对n取余为0判断
class Solution:
def isPowerOfThree(self, n: int) -> bool:
return n > 0 and 1162261467 % n == 0