My solution in Java


  • 0
    A
    /**
     *Basically if number is power of 3 if we repeatedly divide by 3 we should get 1 and remainder should be 0
    */
    
    public boolean isPowerOfThree(int n) {
            while ((n%3 == 0) && ((n = n/3) >= 1)) {
            }
            if (n == 1)
                return true;
            else
                return false;
        }

  • 0
    E

    You are not supposed to use a while loop as indicated in the description :)


Log in to reply
 

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