206. 反转链表https://leetcode.cn/problems/reverse-linked-list/
pre(previous),cur(current),nxt,(链表:前面是谁,我是谁,后面是谁)
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
#反转链表
class Solution:
def reverseList(self,head:Optional[ListNode]) -> Optional[ListNode]:
pre = None
cur = head
while cur:
nxt = cur.next
cur.next = pre
pre = cur
cur = nxt
return pre