Another elegant solution for easy LC problem.
class Solution {
fun fizzBuzz(n: Int): List<String> {
return (1..n).map {
when {
it % 3 == 0 && it % 5 == 0 -> "FizzBuzz"
it % 3 == 0 -> "Fizz"
it % 5 == 0 -> "Buzz"
else -> "$it"
}
}
}
}
Runtime: 184 ms, faster than 45.95% of Kotlin online submissions for Fizz Buzz.
Memory Usage: 36.5 MB, less than 100.00% of Kotlin online submissions for Fizz Buzz.