Merge 2 Linked Lists (Ordered) In Place

PHOTO EMBED

Tue Sep 28 2021 17:52:09 GMT+0000 (Coordinated Universal Time)

Saved by @Adorism80 #javascript

function mergeLists(headone, headtwo) {
  if (headone === null || headtwo === null) {
    return headone === null ? headtwo : headone
  }

  let p1 = headone.val <= headtwo.val ? headone : headtwo
  let p2 = p1 === headone ? headtwo : headone
  const head = p1

  head.next = mergeLists(p1.next, p2)

  return head
}
content_copyCOPY