def reverse_node_list(head):if not head or not head.next:return headprev = Nonewhile head:curr = headhead = head.nextcurr.next = prevprev = currreturn prev
设置三个指针, prev指向前一个节点, head 指向现在的节点, curr指向下一个要去的节点
初始化:
prev空
head表头
先保留当前节点
挪动指针
当前节点反转
挪动prev