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;
    }
};
原文地址:https://www.cnblogs.com/pk28/p/8485322.html