Link: https://leetcode.com/problems/merge-two-sorted-lists/
Solution:
Topics: linked list, dummy node
Intuition
I don’t know why but I always over complicate this. Lets go over it properly once and for all! There is no need for contrived splicing logic or temp variables! You can literally treat this exactly like like merging two sorted arrays if the variables are set up correctly.
Create a dummy node and a head pointing to the dummy node. Why? Because this will eliminate the need for dumb pointer logic. The head
pointer will “pick up” the list values, no need for temp variables!
I’m marking this as hard, not because it is but because I always go for the most complicated way implementation and I’m sick of it.
Implementation