class Solution:
def reverseList(self, head: ListNode) -> ListNode:
newhead=None #存储新链表头节点位置
while head:
nex=head.next #存储原链表下一个节点位置
head.next=newhead
newhead=head
head=nex
return newhead
leetcode-反转链表(python)
猜你喜欢
转载自blog.csdn.net/weixin_40876685/article/details/88722025
今日推荐
周排行