这是LeetCode里合并两个有序链表的题,实在不知道哪里写错了。请大家受累看下

将两个升序链表合并为一个新的 升序 链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。

class Solution {
public:
    ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) 
    {
        ListNode * retList = new ListNode();
        if(l1 == NULL && l2 == NULL)
            return NULL;
        else if(l1 == NULL) 
            return l2;
        else 
           return NULL;
        while (!l1 && !l2)
        {
            if(l1->val < l2->val)
            {
                retList = l1;
                l1 = l1->next;
                retList = retList->next;
            }
            else
            {
                retList = l2;
                l2 = l2->next;
                retList = retList->next;
            }
        }

        retList = (l1 ? l1 : l2);
        return retList;
    }
};

img