Java Solution, two different ways depending submitted here or eclipse


  • -8
    R
    static boolean isPowerOfThree(int n) {
        if ((n/3) == 1){
            return true;
        }
        if ((n % 3) != 0){
            return false;
        }
        else {
            return isPowerOfThree(n/3);
        }
    }
    

    This code worked for me in eclispe ^

    static boolean isPowerOfThree(int n) {
        if ((n/=3) == 1){
            return true;
        }
        if ((n % 3) != 0){
            return false;
        }
        else {
            return isPowerOfThree(n/=3);
        }
    }
    

    This code worked here, note the "/=" replacement for "/" ^


  • 1
    D

    run time error


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.