您的位置:首页 > 其它

【leetcode】Power of Three

2016-06-02 13:46 429 查看

Question

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?

Code

#include<iostream>
using namespace std;

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

int main() {
Solution so;
int n = 9;
cout << so.isPowerOfThree(n) << endl;
system("pause");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: