leetcode 326. Power of Three

Given an integer, write a function to determine if it is a power of three.

判断一个数,是不是3的n次幂。直接换底公式求解

class Solution {
public:
    bool isPowerOfThree(int n) {
        double x = log10(n) / log10(3.0);
        if (x == int(x)) return true;
        return false;
    }
};
posted on 2018-02-28 19:22  Beserious  阅读(85)  评论(0编辑  收藏  举报