We use another method `private boolean isUgly(int num, int n)`

to handle `2`

, `3`

, `5`

without produce duplicate codes.

Use `num == 0`

and `num == 1`

to deal with end condition.

The remaining logic is clean.

Solution:

```
public class Solution {
public boolean isUgly(int num) {
if (num == 0) { return false; }
if (num == 1) { return true; }
return isUgly(num, 2) || isUgly(num, 3) || isUgly(num, 5);
}
private boolean isUgly(int num, int n) {
return num % n == 0 ? isUgly(num / n) : false;
}
}
```