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?
class Solution(object): def isPowerOfThree(self, n): """ :type n: int :rtype: bool """ #method 1 return n > 0 and 3 ** round(math.log(n,3)) == n #method 2 if n < 0: return False if n == 0: return False re = math.log(n) / math.log(3.0) i = round(re,0) if abs(re-i) < 1e-10: return True else: return False
相关推荐
Power Query学习素材——学生成绩表 讲解Power Query的合并查询功能所用。
Power View——卡片.pdf 学习资料 复习资料 教学资源
The power of thinking Big.docx
Application of a Three-level NPC Inverter as a Three-Phase Four-Wire Power Quality Compensator by Generalized 3DSVM.pdf
Power Query学习文件——NBA全明星清单 如何整理大数据量的Excel信息,快速分析汇总。
Eduard Cerny, Surrendra Dudani, John Havlicek, Dmitry Korchemny (auth.) - SVA_ The Power of Assertions in SystemVerilog-Springer International Publishing (2015)
Power力量——控制指引他人的自我价值.doc
The Power of Technology.pdf
Quiet The Power of Introverts,此文件制作测试用途,请支持正版。多看中译版购买地址:http://www.duokan.com/book/24477
北大POJ2109-Power of Cryptography 解题报告+AC代码
该作品最终成绩88分,简单易做,附带实验报告,实验报告里有详细的制作步骤,功能不是很强大,不过绝对可以完成老师的要求!希望能帮到需要的友友……
Fundamentals of Power Semiconductor Devices provides an in-depth treatment of the physics of operation of power semiconductor devices that are commonly used by the power electronics industry....
详细讲解了PowerPC的体系架构 包括:处理器架构、cache、指令、操作系统
Author David Herman, with his years of experience on Ecma’s JavaScript standardization committee, illuminates the language’s inner workings as never before—helping you take full advantage of ...
微软Power Query的操作基础:数据类型、添加自定义列、拆分列
powerbuilder源代码之自来水收费系统。
powerbuilder源代码下载之考勤管理系统。
powerbuilder源代码之图书管理系统。
powerbuilder源代码下载之工资自动生成系统。