原题:
Given an integer, write a function to determine if it is a power of three.
Follow up:
Could you do it without using any loop / recursion?
这个题目本身没有任何难度,也是easy等级,但是题目要求不能使用循环和迭代,解法如下:
import math
class Solution(object):
def isPowerOfThree(self, n):
"""
:type n: int
:rtype: bool
"""
return False if n <= 0 else n == pow(3, round(math.log(n, 3)))