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 lists2sort(vals)3rebuild a list from vals
state
- l1[1,2,4]
- l2[1,3,4]
warming up the animation
Merge two sorted linked lists into one sorted list by splicing their nodes together, and return its head.
▸1vals ← all values of both lists2sort(vals)3rebuild a list from vals
line 1Merge two SORTED lists into one sorted list. Lazy way: dump every value into an array and sort it.