The algorithm: Create a dummy node. Initialize curr = dummy. While both lists have nodes: - If list1.val <= list2.val, attach list1 and advance list1 - Otherwise, attach list2 and advance list2 - Advance curr Attach the remaining nodes from whichever list isn't empty Return dummy.next (the real head) The dummy node eliminates special cases for the first insertion.
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
$ curl repovive.com/roadmaps/maang-interview-prep/linked-lists/merge-two-sorted-lists-solution
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██████████████████████████████████████████████████████████████████████████████████████████████