@@ -0,0 +1,2387 @@
+package main.algorithm.leetcode;%0A%0Aimport org.junit.Test;%0A%0A/**%0A * Title : main.algorithm.leetcode %3Cbr%3E%0A * Description :%0A *   %3Cp%3E Merge two sorted linked lists and return it as a new list.%0A *   %3Cp%3E The new list should be made by splicing together the nodes of the first two lists.%0A *   %3Cp%3E Input: 1-%3E2-%3E4, 1-%3E3-%3E4%0A *   %3Cp%3E Output: 1-%3E1-%3E2-%3E3-%3E4-%3E4%0A *   %3Cp%3E Runtime: 0 ms, faster than 100.00%25 of Java online submissions for Merge Two Sorted Lists.%0A *   %3Cp%3E Memory Usage: 37 MB, less than 97.90%25 of Java online submissions for Merge Two Sorted Lists.%0A * @author chile%0A * @version 1.0%0A * @date 2019/4/25 13:42%0A */%0Apublic class MergeTwoSortedLists %7B%0A    /**%0A     * Definition for singly-linked list.%0A     */%0A    public class ListNode %7B%0A        int val;%0A%0A        ListNode next;%0A%0A        ListNode(int x) %7B%0A            val = x;%0A        %7D%0A    %7D%0A%0A    class Solution %7B%0A%0A        public ListNode mergeTwoLists(ListNode l1, ListNode l2) %7B%0A            if (l1 == null) return l2;%0A            if (l2 == null) return l1;%0A%0A            ListNode r = new ListNode(l1.val %3E l2.val ? l2.val : l1.val);%0A%0A            ListNode rr = r;%0A%0A            while (true) %7B%0A                if (l1 == null && l2 != null) %7B%0A                    r.next = l2;%0A                    break;%0A                %7D%0A                if (l1 != null && l2 == null) %7B%0A                    r.next = l1;%0A                    break;%0A                %7D%0A                if (l1 != null && l2 != null) %7B%0A                    if (l1.val %3E l2.val) %7B%0A                        r.next = l2;%0A                        r = r.next;%0A                        l2 = l2.next;%0A                    %7D else %7B%0A                        r.next = l1;%0A                        r = r.next;%0A                        l1 = l1.next;%0A                    %7D%0A                    continue;%0A                %7D%0A                if (l1 == null && l2 == null) %7B%0A                    break;%0A                %7D%0A            %7D%0A%0A            return rr.next;%0A        %7D%0A    %7D%0A%0A    @Test%0A    public void test1() %7B%0A        ListNode l1 = new ListNode(1);%0A        l1.next = new ListNode(2);%0A        l1.next.next = new ListNode(4);%0A        ListNode l2 = new ListNode(1);%0A        l2.next = new ListNode(3);%0A        l2.next.next = new ListNode(4);%0A        ListNode r = new Solution().mergeTwoLists(l1, l2);%0A        while (r.next != null) %7B%0A            System.out.print(r.val);%0A            r = r.next;%0A        %7D%0A    %7D%0A%7D%0A

Merge Two Sorted Lists