How to merge two LinkedLists in Java recursively?

Please correct me. This code doesn't work. Can someone fix it please.

class Solution {
    public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
        if(l1==null){
            return l2;
        }else if(l2==null){
            return l1;
        }else{
            ListNode forward=l1.next;//2-3-4
            l1.next=l2;
            l1.next=mergeTwoLists(l1.next,l2.next);
            return l1;
        }
    }
}

Input: 
[1,2,3]  
[4,5,6]

Output: 
[1,4,2,5,3,6]
Comments (0)