添加 206反转链表 Kotlin实现

This commit is contained in:
wz-mibookwindows
2021-08-07 11:39:11 +08:00
parent 91c6ecdee9
commit 9dd846ec55

View File

@ -319,7 +319,20 @@ def reverse(pre, cur)
reverse(cur, tem) # 通过递归实现双指针法中的更新操作 reverse(cur, tem) # 通过递归实现双指针法中的更新操作
end end
``` ```
Kotlin:
```Kotlin
fun reverseList(head: ListNode?): ListNode? {
var pre: ListNode? = null
var cur = head
while (cur != null) {
val temp = cur.next
cur.next = pre
pre = cur
cur = temp
}
return pre
}
```
----------------------- -----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw) * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)