mirror of
				https://github.com/krahets/hello-algo.git
				synced 2025-11-04 06:07:20 +08:00 
			
		
		
		
	Fix the comment in recursion.kt (#1177)
* feat(kotlin): add kotlin code for utils file. * Update ListNode.kt * Update PrintUtil.kt * fix: add the header comment for linkedlist_stack class. * fix(kotlin): fix the kotlin file name. * delete blank line in main function * add comment for class head. * delete the old file. * fix the created time * delete blank line beneath files. * keep tailRecur function consistent with other. * Update recursion.kt --------- Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
		@ -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")
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user