• + 0 comments

    We can simplify your solution even furthur. The following is almost the same but appeared easier to understand to me. Actually the else block is simplified.

    if((headA==null)&&(headB==null)) return null; if((headA!=null)&&(headB==null)) return headA; if((headA == null)&&(headB!=null)) return headB;

    if(headA.data<headB.data){
        headA.next = mergeLists(headA.next, headB);
        return headA;
    } else{
         headB.next = mergeLists(headA, headB.next);
        return headB;
    }