LeetCode:Power of Three

given an integer,write a function to determine if it is a power of three.

class Solution {
public:
    bool isPowerOfThree(int n) {
        if(n<1) return false;
        else if(n==1) 
            return true;
        else
          return n%3==0&&isPowerOfThree(n/3);
        
    }
};

 

posted @ 2016-01-08 18:41  尾巴草  阅读(134)  评论(0编辑  收藏  举报