leetcode 326 Power of Three (python)

原题:
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)))
posted @ 2016-01-09 14:53  cotyb  阅读(916)  评论(0编辑  收藏  举报
AmazingCounters.com