3的幂

class Solution {
public:
    bool isPowerOfThree(int n) {
        if(n<=0)return false;
        const int maxint=0x7fffffff;
        int k=log(maxint)/log(3);
        int answer=pow(3,k);
        return (answer%n==0);
    
    }
};
1 class Solution {
2 public:
3     bool isPowerOfThree(int n) {
4    while(n&&n%3==0){
5        n/=3;
6    }
7     return n==1;
8     }
9 };

猜你喜欢

转载自www.cnblogs.com/cwfzzz/p/9032280.html
3-3
3-1
3-6
3-4