Reverse Linked List
EasyLinked Lists
Reverse a singly linked list.
The list is represented as a nested object: { val: 1, next: { val: 2, next: { val: 3, next: null } } }
Example:
Input: head = [1,2,3,4,5]
Output: [5,4,3,2,1]
Note: The function receives head (the first node) and should return the new head (the first node of the reversed list).
Constraints:
- •
0 <= number of nodes <= 5000 - •
-5000 <= Node.val <= 5000
Reverse Linked List
EasyLinked Lists
Reverse a singly linked list.
The list is represented as a nested object: { val: 1, next: { val: 2, next: { val: 3, next: null } } }
Example:
Input: head = [1,2,3,4,5]
Output: [5,4,3,2,1]
Note: The function receives head (the first node) and should return the new head (the first node of the reversed list).
Constraints:
- •
0 <= number of nodes <= 5000 - •
-5000 <= Node.val <= 5000
Press Run or Ctrl+Enter to execute