您的位置:首页 > 其它

Leetcode 326 Power of Three

2016-05-19 16:28 363 查看
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?

1162261467 = 3^19为int范围内最大, 如果一个数为3的n方,则该数需要能被这个最大的数整除。

class Solution(object):
def isPowerOfThree(self, n):
return n>0 and 1162261467%n==0
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: