剑指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

 

posted @ 2023-01-04 11:42  BJFU-VTH  阅读(15)  评论(0编辑  收藏  举报