Past Challenges

20. Reverse Linked List

75%

Write a function that, given the head of a singly linked list, reverses the list. Return the root node of the reversed list.

Example: Input: 1 -> 2 -> 3 -> 4 -> 5 Output: 5 -> 4 -> 3 -> 2 -> 1

Make sure you return your solution, don't print!

Python3

# Singly Linked List Definition
class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next

def solve(head):
    pass

Submit

GridFailuresHints Test Cases Attempts