[Leetcode] [021] Merge Sorted Lists (Java)

Source: Internet
Author: User

The title is here: https://leetcode.com/problems/merge-two-sorted-lists/

"Tags" Linked List

The topic "Problem analysis" is the transformation of the merge sort in the Linked list. Not much, directly on the code.

1      PublicListNode mergetwolists (listnode L1, ListNode L2) {2ListNode Dummyhead =NewListNode (-1);3ListNode node =Dummyhead;4          while(L1! =NULL&& L2! =NULL) {5             if(L1.val <=l2.val) {6Node.next =L1;7L1 =L1.next;8}Else {9Node.next =L2;TenL2 =L2.next; One             } Anode =Node.next; -         } -         //Append the remaining list theNode.next = (L1! =NULL) ?L1:l2; -         returnDummyhead.next; -}

[Leetcode] [021] Merge Sorted Lists (Java)

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.