Compute Fibonacci in Kotlin

Posted by yhuang
Public (Editable by Users)
Kotlin
None
Edit
fun main() {
    println(fibonacci(10))
}

fun fibonacci(n: Int): Long {
    if (n == 0) return 0
    if (n == 1) return 1
    return fibonacci(n - 1) + fibonacci(n - 2)
}