class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next
def reverseList(head):
current = head
previous = None
while current is not None:
保存当前节点的下一个节点
next_node = current.next
反转当前节点的指针
current.next = previous
# 更新指针位置
previous = current
current = next_node
返回反转后的链表头节点
return previous