https://www.nowcoder.com/practice/d8b6b4358f774294a89de2a6ac4d9337?tpId=13&tqId=11169&rp=1&ru=% 2fta%2fcoding-interviews&qru=%2fta%2fcoding-interviews%2fquestion-ranking&tpage=1 Test instructions Two lists are lined up, to merge them together analyze make a predecessor node point to the first node dummycur point to dummy code/*public class ListNode { int Val; listnode next = null; listnode (int val) { this.val = Val; }}*/public class Solution { public ListNode Merge (listnode list1,listnode list2) { listnode dummy = new ListNode (0); listnode cur = dummy; while (list1!=null && list2!=null) { if (List1.val < List2.val) { cur.next = list1; list1 = list1.next; cur = cur.next; }else{ cur.next = list2; list2 = list2.next; cur = cur.next; } } if (List1! = null) {Cur.next = List1;} if (List2! = null) {CUR.next = List2;} return dummy.next; }}
Sword refers to offer------merge sorted list