public static Node mergeTwoList(Node head1, Node head2) { // 递归结束条件
if (head1 == null && head2 == null) {
return null;
}
if (head1 == null) {
return head2;
}
if (head2 == null) {
return head1;
} // 合并后的链表
Node head = null;
if (head1.data > head2.data) { // 把head较小的结点给头结点
head = head2; // 继续递归head2
head.next = mergeTwoList(head1, head2.next);
} else {
head = head1;
head.next = mergeTwoList(head1.next, head2);
}
return head;
}