Power of Three

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

class Solution {
public:
    bool isPowerOfThree(int n) {
        if(n <= 0)   return false;

        return n == pow(3, round( log(n)/log(3) ) );
    }
};

results matching ""

    No results matching ""