Java 2ms ac one circulation


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

Log in to reply
 

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