讨论/《画解剑指 Offer》 - 剑指 Offer 24. 反转链表/
《画解剑指 Offer》 - 剑指 Offer 24. 反转链表
共 1 个回复

补一个Python

class Solution:
    def reverseList(self, head: ListNode) -> ListNode:
        if not head or not head.next:
            return head
        dummy = None
        cur = head
        while cur:
            temp = cur.next
            cur.next = dummy
            dummy = cur
            cur = temp
        return dummy