1 public class Solution { 2 public ListNode mergeTwoLists(ListNode l1, ListNode l2) { 3 ListNode safe = new ListNode(-1); 4 ListNode pre = safe; 5 while(l1!=null && l2!=null){ 6 if(l1.val<l2.val){ 7 pre.next = l1; 8 l1 = l1.next; 9 } 10 else{ 11 pre.next = l2; 12 l2 = l2.next; 13 } 14 pre = pre.next; 15 } 16 if(l1!=null){ 17 pre.next = l1; 18 } 19 if(l2!=null){ 20 pre.next = l2; 21 } 22 return safe.next; 23 } 24 }
相关文章
- 12-21Leetcode 4: Median of Two Sorted Arrays
- 12-21LeetCode-4-Median of Two Sorted Arrays
- 12-21刷题4. Median of Two Sorted Arrays
- 12-21Leetcode: 4.Median of Two Sorted Arrays两数相加寻找两个有序数组的中位数
- 12-214. Median of Two Sorted Arrays
- 12-21Leetcode 88 Merge Sorted Array STL
- 12-21[Leetcode 44]合并有序列表Merge k Sorted Lists
- 12-21【LeetCode算法题库】Day7:Remove Nth Node From End of List & Valid Parentheses & Merge Two Lists
- 12-21[LeetCode] Merge Sorted Array
- 12-21leetCode 4. Median of Two Sorted Arrays