author: Blankj blog : http://blankj.com time : 2017/04/29 desc :
| 11 | * </pre> |
| 12 | */ |
| 13 | public class Solution { |
| 14 | public ListNode mergeTwoLists(ListNode l1, ListNode l2) { |
| 15 | ListNode head = new ListNode(0); |
| 16 | ListNode temp = head; |
| 17 | while (l1 != null && l2 != null) { |
| 18 | if (l1.val < l2.val) { |
| 19 | temp.next = l1; |
| 20 | l1 = l1.next; |
| 21 | } else { |
| 22 | temp.next = l2; |
| 23 | l2 = l2.next; |
| 24 | } |
| 25 | temp = temp.next; |
| 26 | } |
| 27 | temp.next = l1 != null ? l1 : l2; |
| 28 | return head.next; |
| 29 | } |
| 30 | |
| 31 | public static void main(String[] args) { |
| 32 | Solution solution = new Solution(); |
| 33 | ListNode listNode0 = ListNode.createTestData("[1,3,5,7,9]"); |
| 34 | ListNode listNode1 = ListNode.createTestData("[2,4,6,8,10]"); |
| 35 | ListNode.print(listNode0); |
| 36 | ListNode.print(listNode1); |
| 37 | ListNode.print(solution.mergeTwoLists(listNode0, listNode1)); |
| 38 | } |
| 39 | } |
nothing calls this directly
no outgoing calls
no test coverage detected