mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
添加 206反转链表 Kotlin实现
This commit is contained in:
@ -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)
|
||||||
|
Reference in New Issue
Block a user