[leetcode]326. Power of Three

problem

326. Power of Three

solution: Iteration

class Solution {
public:
    bool isPowerOfThree(int n) {
        if(n<1) return false;//err.
        while(n%3==0)
        {
            n /= 3;
        }
        return n==1;//err.     
    }
};

 

 

 

ref

1. Leetcode_326_Power of Three;

2. GrangYang;

3. A summary of `all` solutions;

end

posted on 2019-02-22 11:26  鹅要长大  阅读(145)  评论(0编辑  收藏  举报

导航