class Solution {
public:
    ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) {
        ListNode *dummy = new ListNode(-1), *cur = dummy;
        while (l1 && l2) {
            if (l1->val < l2->val) {
                cur->next = l1;
                l1 = l1->next;
            } else {
                cur->next = l2;
                l2 = l2->next;
            }
            cur = cur->next;
        }
        cur->next = l1 ? l1 : l2;
        return dummy->next;
    }
};

相关文章:

  • 2021-06-03
  • 2022-01-02
  • 2022-01-16
  • 2021-10-01
  • 2021-06-02
  • 2021-05-22
猜你喜欢
  • 2022-01-18
相关资源
相似解决方案