AC java solution


  • 0
    M
    public boolean isPowerOfThree(int n) {
    
        while(n>=1){
            if(n==1) return true;
            int last = n%10;
            
            if((last==1||last==3||last==7||last==9) && n%3==0) n/=3;
            else return false;
        }    
        
        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.