剑指24. 反转链表
问题链接
https://leetcode.cn/problems/fan-zhuan-lian-biao-lcof/description/
解题思路
参考上一个题目。
代码
class ListNode: def __init__(self, x): self.val = x self.next = None class Solution: def reverseList(self, head): if head is None or head.next is None: return head last = self.reverseList(head.next) head.next.next = head head.next = None return last