206. Reverse Linked List
Given the head of a singly linked list, reverse it and return the new head.
def reverse_list(head):
prev = None
while head:
nxt = head.next
head.next = prev
prev = head
head = nxt
return prev
Classic three-pointer shuffle: before overwriting head.next, save it as nxt so the rest of the list isn't lost. prev ends up as the new head once head runs off the end.