导航

LeetCode Power of Three

Posted on 2016-03-27 02:15  CSU蛋李  阅读(131)  评论(0编辑  收藏  举报

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?

 

最大的int 型3的幂是1162261467

所以只要1162261467%3==0就是3的幂

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