39. leetcode 326. Power of Three

mac2022-06-30  64

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为底的对数则没有这个问题。

 

转载于:https://www.cnblogs.com/vincent93/p/6686634.html

最新回复(0)