Newer
Older
# Write a function that, given the head of a singly linked list, reverses the list.
# Return the root node of the reversed list.
def solve(head):
current = head
prev = None
while current:
temp_next = current.next
current.next = prev
prev = current
current = temp_next
return prev