leetcode——326——Power of Three

来源:互联网 发布:如何卸载mac上的app 编辑:程序博客网 时间:2024/06/15 05:28

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

class Solution {public:    bool isPowerOfThree(int n) {        double result =  log10(n) / log10(3);        return (result-int(result)==0)?true:false;    }};


0 0