Simple C# solution


  • 0
    S
    public class Solution {
        public bool IsUgly(int num) 
        {
            if(num<1)
                return false;
            var dList = new List<int>{2,3,5};
            while(num>1)
            {
                var d = dList.FirstOrDefault(n => num%n == 0);
                if(d == 0)
                    return false;
                num/=d;
            }
            return num==1;
        }
    }
    

Log in to reply
 

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