LC 206. Reverse Linked List
1/**
2 * Definition for singly-linked list.
3 * function ListNode(val, next) {
4 * this.val = (val===undefined ? 0 : val)
5 * this.next = (next===undefined ? null : next)
6 * }
7 */
8/**
9 * @param {ListNode} head
10 * @return {ListNode}
11 */
12var reverseList = function (head) {
13 if (head === null || head.next === null) return head
14 const newHead = reverseList(head.next)
15 head.next.next = head
16 head.next = null
17 return newHead
18};