1. public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
    2. ListNode head = new ListNode();
    3. while (list1 != null) {
    4. while (list2 != null) {
    5. ListNode temp = head;
    6. int val1 = list1.val;
    7. int val2 = list2.val;
    8. int maxVal = Math.max(list1.val, list2.val);
    9. temp.next = new ListNode(maxVal); // 较大者在后面
    10. temp = temp.next; // 指针向前移动
    11. if (val1 > val2) {
    12. list2 = list2.next;
    13. } else {
    14. break;
    15. }
    16. }
    17. list1 = list1.next;
    18. }
    19. return head;
    20. }