C++,beats 100%,use log math and the method of double comparison


  • 0
    B

    class Solution {
    public:
    bool isPowerOfThree(int n) {
    double temp = log(n)/log(3);
    int intTemp = (int)(temp+0.5);
    if(abs(temp-intTemp)<1e-10)
    return true;
    else return false;
    }
    };


  • 0
    X

    hi, could you please explain why it should be log10 instead of log2 or other bases


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.