C# easy to understand solution


  • 0
    Y
    public class Solution {
        public bool IsUgly(int num) {
            if(num==1)
                return true;
            if(num < 2)
                return false;
            if(num==2||num==3||num==5)
                return true;
            if(num%2==0)
                return IsUgly(num/2);
            if(num%3==0)
                return IsUgly(num/3);
            if(num%5==0)
                return IsUgly(num/5);
                
            return false;
        }
    }

Log in to reply
 

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