码迷,mamicode.com
首页 > 其他好文 > 详细

39. leetcode 326. Power of Three

时间:2017-04-09 22:06:07      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:alt   技术   没有   精度   without   integer   分享   str   int   

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

标签:alt   技术   没有   精度   without   integer   分享   str   int   

原文地址:http://www.cnblogs.com/vincent93/p/6686634.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!