Your free access ends in 7 days — and you haven’t tried it yet. Watch one algorithm run, start to finish. It takes about two minutes.

Try one problem
0
Problem

Merge Two Sorted Lists

LeetCode #21Easy
Splice the smaller head · dummy node

Merge two sorted linked lists into one sorted list by splicing their nodes together, and return its head.

Asked atAmazonMicrosoftAppleAdobe
step 1 / 11
list 1
list 2
1
2
4
1
3
4
[0][1][2][3][4][5]
collected
Naive · collect + sort
1vals ← all values of both lists
2sort(vals)
3rebuild a list from vals
state
  • l1[1,2,4]
  • l2[1,3,4]

line 1Merge two SORTED lists into one sorted list. Lazy way: dump every value into an array and sort it.