原题:
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)))

相关文章:

  • 2022-12-23
  • 2021-11-24
  • 2021-12-07
  • 2022-12-23
  • 2021-07-29
  • 2022-12-23
  • 2021-08-23
猜你喜欢
  • 2021-12-02
  • 2021-09-04
  • 2022-01-29
  • 2021-08-26
  • 2021-11-29
  • 2022-02-17
相关资源
相似解决方案