(ListNode left, ListNode right)
| 19 | return slow; |
| 20 | } |
| 21 | public ListNode merge(ListNode left, ListNode right){ |
| 22 | ListNode dummy = new ListNode(); |
| 23 | ListNode tail = dummy; |
| 24 | |
| 25 | while(left != null && right != null){ |
| 26 | if(left.val < right.val){ |
| 27 | tail.next = left; |
| 28 | left = left.next; |
| 29 | }else{ |
| 30 | tail.next = right; |
| 31 | right = right.next; |
| 32 | } |
| 33 | tail = tail.next; |
| 34 | } |
| 35 | if(left != null){ |
| 36 | tail.next = left; |
| 37 | } |
| 38 | if(right != null){ |
| 39 | tail.next = right; |
| 40 | } |
| 41 | return dummy.next; |
| 42 | } |
| 43 | public ListNode sortList(ListNode head) { |
| 44 | if(head == null || head.next == null){ |
| 45 | return head; |
no outgoing calls
no test coverage detected