Answers for "js combine linked list"

2

reverse a linked list javascript

// O(n) time & O(n) space
function reverse(head) {
  if (!head || !head.next) {
    return head;
  }
  let tmp = reverse(head.next);
  head.next.next = head;
  head.next = undefined;
  return tmp;
}
Posted by: Guest on January-22-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language