@@ -0,0 +1,1655 @@
+package com.matao;%0A%0Aimport com.matao.common.ListNode;%0A%0A/**%0A * Created by matao on 2019-01-06.%0A * %3Cp%3E%0A * %E8%BE%93%E5%85%A5%E4%B8%A4%E4%B8%AA%E9%80%92%E5%A2%9E%E6%8E%92%E5%BA%8F%E7%9A%84%E9%93%BE%E8%A1%A8%EF%BC%8C%E8%A6%81%E6%B1%82%E5%90%88%E5%B9%B6%E5%90%8E%E4%BF%9D%E6%8C%81%E9%80%92%E5%A2%9E%E3%80%82%0A */%0A@SuppressWarnings(%22Duplicates%22)%0Apublic class Q25_MergeSortedLists %7B%0A%0A    public ListNode%3CInteger%3E mergeRecursion(ListNode%3CInteger%3E head1, ListNode%3CInteger%3E head2) %7B%0A        if (head1 == null) return head2;%0A        if (head2 == null) return head1;%0A%0A        ListNode%3CInteger%3E p = head1;%0A        ListNode%3CInteger%3E q = head2;%0A        ListNode%3CInteger%3E mergedHead;%0A%0A        if (p.val %3C q.val) %7B%0A            mergedHead = p;%0A            mergedHead.next = mergeRecursion(p.next, q);%0A        %7D else %7B%0A            mergedHead = q;%0A            mergedHead.next = mergeRecursion(p, q.next);%0A        %7D%0A%0A        return mergedHead;%0A    %7D%0A%0A    public ListNode%3CInteger%3E merge(ListNode%3CInteger%3E head1, ListNode%3CInteger%3E head2) %7B%0A        if (head1 == null) return head2;%0A        if (head2 == null) return head1;%0A%0A        ListNode%3CInteger%3E p = head1;%0A        ListNode%3CInteger%3E q = head2;%0A        ListNode%3CInteger%3E r;%0A        ListNode%3CInteger%3E mergedHead;%0A        if (p.val %3C q.val) %7B%0A            mergedHead = p;%0A            r = p;%0A            p = p.next;%0A        %7D else %7B%0A            mergedHead = q;%0A            r = q;%0A            q = q.next;%0A        %7D%0A%0A        while (p != null && q != null) %7B%0A            if (p.val %3C q.val) %7B%0A                r.next = p;%0A                p = p.next;%0A            %7D else %7B%0A                r.next = q;%0A                q = q.next;%0A            %7D%0A            r = r.next;%0A        %7D%0A%0A        if (p != null) %7B%0A            r.next = p;%0A        %7D else %7B%0A            r.next = q;%0A        %7D%0A%0A        return mergedHead;%0A    %7D%0A%7D%0A

add Q25 MergeSortedLists