Easy understood java solution without recursion


  • -1
    J
    public boolean isPowerOfThree(int n) {
        if(n <=0)
            return false;
        if(n==1)
            return true;
        long x =1;
        while(x < n){
            x *= 3;
        }
        
        return x==n;
        
    }

  • 0
    J

    but you used loop.
    Could you do it without using any loop / recursion?


Log in to reply
 

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