diff --git a/problems/0206.翻转链表.md b/problems/0206.翻转链表.md index ec6f3dca..3e2a22be 100644 --- a/problems/0206.翻转链表.md +++ b/problems/0206.翻转链表.md @@ -164,6 +164,25 @@ class Solution { } ``` +```java +// 从后向前递归 +class Solution { + ListNode reverseList(ListNode head) { + // 边缘条件判断 + if(head == null) return null; + if (head.next == null) return head; + + // 递归调用,翻转第二个节点开始往后的链表 + ListNode last = reverseList(head.next); + // 翻转头节点与第二个节点的指向 + head.next.next = head; + // 此时的 head 节点为尾节点,next 需要指向 NULL + head.next = null; + return last; + } +} +``` + Python迭代法: ```python #双指针