首页 > 代码库 > 39. leetcode 326. Power of Three

39. leetcode 326. Power of Three

326. Power of Three

                      

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?

思路:看这个数取以3为底的对数结果是否为整数,C++中只有自然对数函数log()和以10为底的对数函数log10(),所以要借助换底公式。此处用自然对数会有精度问题,用以10为底的对数则没有这个问题。

技术分享

 

39. leetcode 326. Power of Three