01 · Question
Given the head of a singly linked list, reverse the list, and return the reversed list.
02 · Solution
1def reverseList(head: Optional[ListNode]) -> Optional[ListNode]:2 prev = None3 cur = head4 5 while cur:6 nxt = cur.next7 cur.next = prev8 prev = cur9 cur = nxt10 11 return prev