https://leetcode-cn.com/problems/fan-zhuan-lian-biao-lcof/
    点击查看【bilibili】

    1. # Definition for singly-linked list.
    2. # class ListNode(object):
    3. # def __init__(self, x):
    4. # self.val = x # 数据域
    5. # self.next = None # 指针域
    6. class Solution(object):
    7. def reverseList(self, head):
    8. """
    9. :type head: ListNode
    10. :rtype: ListNode
    11. """
    12. preNode = None
    13. curNode = head
    14. while curNode:
    15. # 创建临时变量存储cur的下一位
    16. temp = curNode.next
    17. # 断开节点
    18. curNode.next = preNode
    19. # 处理下一位
    20. preNode = curNode
    21. curNode = temp
    22. return preNode