Java Solution, 2ms


  • 0
    public class Solution {
       public boolean isUgly(int num) {
            if (num == 0) return false;
            if(num == 1)return true;       
            return factorize(num);
        }
        private boolean factorize(int num){
            if(num == 1) return true;
            if(num % 5 == 0){
                num = num/5;
                return factorize(num);
            }else if(num % 3 == 0){
                num = num/3;
                return factorize(num);
            }else if(num % 2 == 0){
                num = num/2;
                return factorize(num);
            }
            return false;
        }
    
    }
    

Log in to reply
 

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