> For the complete documentation index, see [llms.txt](https://timmybeeflin.gitbook.io/cracking-leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://timmybeeflin.gitbook.io/cracking-leetcode/math/263.-ugly-number.md).

# 263. Ugly Number

![](/files/-Ml4y8CqnWU9KlSVe2Bi)

![](/files/-Ml4yAsYI8SzVoGs2Gow)

time: O(1)

space: O(1)

```java
class Solution {
    public boolean isUgly(int n) {
        if (n == 1) return true;
        if (n == 0) return false;
        
        while (n % 2 == 0) n /= 2;
        while (n % 3 == 0) n /= 3;
        while (n % 5 == 0) n /= 5;
        return n == 1;
    }
}
```
