Sword refers to offer------consolidated List of sorted

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.