Skip to content

Latest commit

 

History

History
17 lines (13 loc) · 382 Bytes

263.ugly-number.md

File metadata and controls

17 lines (13 loc) · 382 Bytes
fun isUgly(n: Int): Boolean {
    if (n <= 0) return false
    if (n == 1) return true

    var num = n

    // while the number can be divisible by 2 or 3 or 5, keep dividing.
    while (num % 2 == 0) num /= 2
    while (num % 3 == 0) num /= 3
    while (num % 5 == 0) num /= 5

    return num == 1
}