Skip to content
Snippets Groups Projects
20.py 333 B
Newer Older
Iida Pyykkönen's avatar
Iida Pyykkönen committed
# 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