dsa · easy
Reverse Linked List
GreyOrangeLinked ListFoundation
Given the head of a singly linked list, reverse the list and return the reversed list.
Arguments
head— the linked list, given as a Python list of node values
The linked list is provided as a Python list of integers for simplicity; return the reversed list.
**Example 1:** `` Input: [1,2,3,4,5] Output: [5,4,3,2,1] ``
Constraints
0 <= length <= 5000 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: [1,2,3,4,5] Expected: [5,4,3,2,1]
Example 2
Input: [1,2] Expected: [2,1]