Skip to main content

🟢 剑指 Offer 24. 反转链表

LeetCode 提示

题目难度 简单

原题链接 🔗 leetcode

题解 1_偷瞄了.py#

# Definition for singly-linked list.# class ListNode:#     def __init__(self, x):#         self.val = x#         self.next = None
class Solution:    def reverseList(self, head: ListNode) -> ListNode:        p, c, n = None, head, None        while c is not None:            n = c.next            c.next = p            p, c = c, n        return p