# 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:
pre=None
cur=head
while cur:
tmp=cur.next
cur.next=pre #反转
pre=cur
cur=tmp
return pre #返回head
链表的构成
一个结点由存储本身信息的单元‘val’和指向下一节点的指针‘next’构成。从头节点‘head’开始读取,故返回head