36. Reverse Linked List

Given a singly linked list. Write a function ListNode ReverseLinkedList(ListNode head) that reverses the list and returns the new head.
Example 1
Input: head = [1,2]
Output: [2,1]
Explanation:
Example 2
Input: head = []
Output: []
Explanation:
Example 3
Input: head = [1,2,3,4,5]
Output: [5,4,3,2,1]
Explanation:
linked listmedium
JavaScript
Loading...
Line 1, Char 1