diff --git a/problems/0206.翻转链表.md b/problems/0206.翻转链表.md index 52ef6484..7c002382 100644 --- a/problems/0206.翻转链表.md +++ b/problems/0206.翻转链表.md @@ -143,7 +143,25 @@ class Solution { ``` Python: - +```python +#双指针 +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution: + def reverseList(self, head: ListNode) -> ListNode: + cur = head + pre = None + while(cur!=None): + temp = cur.next # 保存一下 cur的下一个节点,因为接下来要改变cur->next + cur.next = pre #反转 + #更新pre、cur指针 + pre = cur + cur = temp + return pre +``` Go: