public ListNode mergeTwoList(ListNode list1 ,ListNode list2){ ListNode preNode = new ListNode(); ListNode pre = preNode; while (list1 != null && list2 != null){ if ( list1.val <= list2.val) { pre.next = list1; list1 = list1.next; }else { pre.next = list2; list2 = list2.next; } pre = pre.next; } if (list1 == null){ pre.next = list2; }else { pre.next = list1; } return preNode.next; }
合并两个有序链表
最新推荐文章于 2024-08-30 18:25:32 发布