剑指 Offer 24. 反转链表

思路

  1. 递归
class Solution:
    def reverseList(self, head: ListNode) -> ListNode:
        def helper(head):
            if head is None or head.next is None:
                return head
            ret = helper(head.next)
            head.next.next = head
            head.next = None
            return ret
        return helper(head)
  1. 双指针
# TODO
posted @ 2020-08-16 14:52  珊珊来迟0  阅读(59)  评论(0编辑  收藏  举报