for Robot Artificial Inteligence

42. Power of Three

|

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

Comments