diff --git a/problems/0206.翻转链表.md b/problems/0206.翻转链表.md index 7db80fe1..d29090d9 100644 --- a/problems/0206.翻转链表.md +++ b/problems/0206.翻转链表.md @@ -228,7 +228,22 @@ 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: Optional[ListNode]) -> Optional[ListNode]: + if not head or not head.next: return head + p = self.reverseList(head.next) + head.next.next = head + head.next = None + return p +``` Go: