class ListNode1 {
int val;
ListNode1 next;
public ListNode1(int value) {
this.val = value;
}
}
public class Solution {
public ListNode1 mergeTwoList(ListNode1 l1, ListNode1 l2) {
ListNode1 preHead = new ListNode1(-1);
ListNode1 cur = preHead;
while (l1 != null && l2 != null) {
if (l1.val < l2.val) {
cur.next = l1;
l1 = l1.next;
} else {
cur.next = l2;
l2 = l2.next;
}
cur = cur.next;
}
cur.next = l1 == null ? l2 : l1;
return preHead.next;
}
}
08-06
215
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)