Java solution beats 97.63%


  • 0
    S

    public boolean isPowerOfThree(int n) {
    while(n>=1){
    if(n==1) return true;
    int last_digit = n%10;
    if((last_digit!=1 && last_digit!=3 && last_digit!=7 && last_digit!=9) || n%3!=0) return false;
    else n/=3;
    }
    return n>0?true:false;
    }


Log in to reply
 

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