题目链接:https://leetcode.cn/problems/reverse-linked-list/
难度:简单
描述:
给你单链表的头节点 head ,请你反转链表,并返回反转后的链表。
题解
# Definition for singly-linked list.# class ListNode:# def __init__(self, val=0, next=None):# self.val = val# self.next = nextclass Solution:def reverseList(self, head: ListNode) -> ListNode:pre = Nonecur = headwhile cur is not None:temp = cur.nextcur.next = prepre = curcur = tempreturn pre
