###### LeetCode21:Merge Two Sorted Lists

Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.

//Definition for singly-linked list.
struct ListNode {
int val;
ListNode *next;
ListNode(int x) : val(x), next(NULL) {}
};

//遍历两个链表，每次取最小值
class Solution {
public:
ListNode *mergeTwoLists(ListNode *l1, ListNode *l2) {

ListNode * head = new ListNode(0);

while (l1 != NULL || l2 != NULL){
ListNode * cur = NULL;
if (l1 == NULL){
cur = l2;
l2 = l2->next;
}
else if (l2 == NULL){
cur = l1;
l1 = l1->next;
}
else{
if (l1->val < l2->val){
cur = l1;
l1 = l1->next;
}
else{
cur = l2;
l2 = l2->next;
}
}
ptr->next = cur;
ptr = ptr->next;
}

}
};

#### LeetCode 21：Merge Two Sorted Lists

2015-05-27 23:08:48

#### Leetcode 21. Merge Two Sorted Lists(C++)

2017-04-24 15:02:29

#### leetcode第21题——*Merge Two Sorted Lists

2016-02-28 10:09:15

#### LeetCode 21 — Merge Two Sorted Lists（C++ Java Python）

2014-02-27 22:06:33

#### LeetCode 21 Merge Two Sorted Lists（合并两个已排序的链表）（Linked List）

2015-11-10 20:38:04

#### Merge Two Sorted Lists -- LeetCode

2014-02-22 23:31:00

#### [LeetCode] 021. Merge Two Sorted Lists (Easy) (C++/Python)

2015-03-04 20:11:32

#### [leetcode-排序]--21. Merge Two Sorted Lists

2017-02-05 16:53:38

#### [C语言][LeetCode][21]Merge Two Sorted Lists

2016-03-04 08:26:24

#### 21. Merge Two Sorted Lists（python）

2016-09-18 21:32:17

## 不良信息举报

LeetCode21:Merge Two Sorted Lists