LeetCode:Power of Three

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)