diff --git a/codes/kotlin/chapter_computational_complexity/recursion.kt b/codes/kotlin/chapter_computational_complexity/recursion.kt index 9de4253fb..38a368b93 100644 --- a/codes/kotlin/chapter_computational_complexity/recursion.kt +++ b/codes/kotlin/chapter_computational_complexity/recursion.kt @@ -37,8 +37,9 @@ fun forLoopRecur(n: Int): Int { return res } -/* Kotlin tailrec 关键词使函数实现尾递归优化 */ +/* 尾递归 */ tailrec fun tailRecur(n: Int, res: Int): Int { + // 添加 tailrec 关键词,以开启尾递归优化 // 终止条件 if (n == 0) return res @@ -73,4 +74,4 @@ fun main() { res = fib(n) println("\n斐波那契数列的第 $n 项为 $res") -} \ No newline at end of file +}