leetcode - Reverse Linked List @ Sat, Feb 18, 2023 9:53 PM
leetcode - Reverse Linked List @ Sun, Feb 19, 2023 9:27 AM
Expand 26 lines ...
27
 */
27
 */
28

28

29
function reverseList(head: ListNode | null): ListNode | null {
29
function reverseList(head: ListNode | null): ListNode | null {
30
+
  // base case, breaking recursive loop
30
  if (head === null || head.next === null) return head;
31
  if (head === null || head.next === null) return head;
31
  const newHead = reverseList(head.next);
32
  const newHead = reverseList(head.next);
32
  head.next.next = head;
33
  head.next.next = head;
Expand 33 lines ...