Java easy solution


  • 1
    D

    Easy solution

    public class Solution {
    public boolean isUgly(int num) {
        do{
            if(num%2==0)          num/=2;
            else if(num%3==0)     num/=3;
            else if(num%5==0)     num/=5;
            else                  break;
        }
        while(num>1);
    
        return (num==1)?true:false;
    }
    

    }


  • 0
    I

    Two tips:

    1. You can replace do-while with a simple while loop.
    2. return (num==1)?true:false; is equivalent to return num == 1;

Log in to reply
 

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