2025.08.08 反转链表
206. 反转链表 - 力扣(LeetCode)
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:if head is None :return Nonecur = headif cur.next is None:return headnxt = cur.nextpre = Nonewhile nxt is not None :cur.next = prepre = curcur = nxtnxt = cur.nextcur.next = prereturn cur