diff --git "a/problems/0206.\347\277\273\350\275\254\351\223\276\350\241\250.md" "b/problems/0206.\347\277\273\350\275\254\351\223\276\350\241\250.md" index 52ef648418..7c00238254 100644 --- "a/problems/0206.\347\277\273\350\275\254\351\223\276\350\241\250.md" +++ "b/problems/0206.\347\277\273\350\275\254\351\223\276\350\241\250.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: