326. Power of Three

Java

public class Solution {
    public boolean isPowerOfThree(int n) {
        if(n<=0) return false;
        while(n>1)
        {
            if(n%3==0)
            n=n/3;
            else
            return false;
        }
        return true;
    }
}

你可能感兴趣的:(326. Power of Three)