class Solution(object):
def isUgly(self, num):
if num == 0:
return False
if num == 1:
return True
for x in (2, 3, 5):
if num % x == 0:
return self.isUgly(num / x)
return False
Simple Python solution

Hey, that's pretty much my algorithm in Java
public class Solution { public boolean isUgly(int num) { if(num <= 0) { return false; } if(num == 1) { return true; } int[] uglyNums = new int[]{2, 3, 5}; for(int i = 0; i < 3; i++) { if(num % uglyNums[i] == 0) { return isUgly(num/uglyNums[i]); } } return false; } }