Easy understanding Java solution


  • 0
    Z
    public boolean isUgly(int num) {
        if(num < 1) return false;
        if(num == 1) return true;
        while(num >1){
            if((num%2 !=0 )&& (num % 3!= 0) && (num % 5 != 0)){
                return false;
            }
            if(num % 2 == 0) num = num/2;
            if(num % 3 == 0) num = num/3;
            if(num % 5 == 0) num = num/5;
        }
        return true;
    }

Log in to reply
 

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