@@ -0,0 +1,1052 @@
+/**%0A * Given an integer, write a function to determine if it is a power of three.%0A * %3Cp%3E%0A * Follow up:%0A * Could you do it without using any loop / recursion?%0A * %3Cp%3E%0A * Tags: Math%0A * Similar Problems: (E) Power of Two, (E) Power of Four%0A */%0Apublic class PowerOfThree %7B%0A%0A    int maxPow3 = (int) Math.pow(3, (int) (Math.log(Integer.MAX_VALUE) / Math.log(3)));%0A%0A    /**%0A     * Check if n's modular of 3 is zero.%0A     * If yes, divide n by 3 and check again.%0A     * Stop till n is 1.%0A     */%0A    public boolean isPowerOfThree(int n) %7B%0A        if (n %3C= 0) return false;%0A        while (n %3E 1 && n %25 3 == 0) %7B%0A            n /= 3;%0A        %7D%0A        return n == 1;%0A    %7D%0A%0A    /**%0A     * Recursive version.%0A     */%0A    public boolean isPowerOfThreeRecursive(int n) %7B%0A        return n %3E 0 && n == 1 && n %25 3 == 0 && isPowerOfThreeRecursive(n / 3);%0A    %7D%0A%0A    /**%0A     * Find the max power of 3 within int range.%0A     * It should be divisible by all power of 3s.%0A     */%0A    public boolean isPowerOfThreeB(int n) %7B%0A        return n %3E 0 && maxPow3 %25 n == 0;%0A    %7D%0A%7D%0A

add Power of Three