[Leetcode]326. Power of Three

来源:互联网 发布:linux怎么进入命令界面 编辑:程序博客网 时间:2024/06/05 10:40

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?

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

0 0
原创粉丝点击