When we talk about the linked list we should think in recursion first.
So we have three things about recursion:
First is when we stop recursion, in this term when the l1 or l2 is null, it is done.
Second is return value in every recursion, we returned the sorted linked list every time.
Last is the procession in every recursion, we compare the l1.val and l2.vale, if l1.val smaller we put the next recursion’s result behind the l1.next. Otherwise, we put that behind the l2.next.