Ugly Number
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
public boolean isUgly(int num) { if(num == 0) return false; else if(num == 1) return true; else if(num % 2 == 0) return isUgly(num / 2); else if(num % 3 == 0) return isUgly(num / 3); else if(num % 5 == 0) return isUgly(num / 5); else return false; } |
Leave A Comment