Created
September 7, 2024 08:10
-
-
Save Sedose/1022d5f5e2c5b84066d3a037454d7c87 to your computer and use it in GitHub Desktop.
Scala solution for https://leetcode.com/problems/ugly-number/description/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@main def main(): Unit = | |
println(isUgly(14)) | |
private val primes = List(2, 3, 5) | |
def isUgly(n: Int): Boolean = | |
var result = n | |
for (prime <- primes) | |
while (result > 1 && result % prime == 0) | |
result /= prime | |
result == 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment