图示

代码
python
# encoding = utf-8
# 开发者:Alen
# 开发时间: 16:06
# "Stay hungry,stay foolish."
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution(object):
def reverseList(self, head):
"""
:type head: Optional[ListNode]
:rtype: Optional[ListNode]
"""
def reverseList(node):
prev = None
cur = head
while cur:
next_temp = cur.next # 保存下一个节点
cur.next = prev # 指针反向
prev = cur # prev前移
cur = next_temp # cur前移
return prev
return reverseList(head)
结果
解题步骤:www.bilibili.com
