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

LeetCode:Power of Three

时间:2016-05-12 11:40:29      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:

Power of Three


Total Accepted: 40773 Total Submissions: 110567 Difficulty: Easy

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?

Credits:
Special thanks to @dietpepsi for adding this problem and creating all test cases.

Subscribe to see which companies asked this question

Hide Tags
 Math
Hide Similar Problems
 (E) Power of Two (E) Power of Four



















c++ code:

class Solution {
public:
    bool isPowerOfThree(int n) {
        double t = log10((double)n) / log10(3.);
        return (int)t == t;
    }
};


LeetCode:Power of Three

标签:

原文地址:http://blog.csdn.net/itismelzp/article/details/51378058

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