21 Merge Two Sorted Lists
水題
class Solution {
public:
ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) {
if (l1 == NULL&&l2 == NULL)return l1;
ListNode *firstNode = new ListNode(0);
ListNode *p = new ListNode(0);
firstNode->next = p;
while (l1 && l2) {
if (l1->val < l2->val) {
p->next = new ListNode(l1->val);
p = p->next;
l1 = l1->next;
}
else {
p->next = new ListNode(l2->val);
p = p->next;
l2 = l2->next;
}
}
if (l1)p->next = l1;
else p->next = l2;
firstNode = firstNode->next->next;
return firstNode;
}
};
相關推薦
Leetcode 21. Merge Two Sorted Lists
oge span solution clas next ini 遞歸解法 else get Merge two sorted linked lists and return it as a new list. The new list should be made by s
leetcode 21 -- Merge Two Sorted Lists
tro leet lan 常見 ber 題目 tty Language node Merge Two Sorted Lists 題目: Merge two sorted linked lists and return it as a ne
21. Merge Two Sorted Lists
oge get clear des eth spl pull cnblogs val 21. Merge Two Sorted Lists Merge two sorted linked lists and return it as a new list
21. Merge Two Sorted Lists【easy】
wol int while min st2 遞歸 merge listnode rst 21. Merge Two Sorted Lists【easy】 Merge two sorted linked lists and return it as a new list.
Leetcode 21. Merge Two Sorted Lists(easy)
tco fin public def div wol lists lis else Merge two sorted linked lists and return it as a new list. The new list should be made by spli
LeetCode.21 - Merge Two Sorted Lists
算法 tput out oge 其中 png 就會 std info Merge two sorted linked lists and return it as a new list. The new list should be made by splicing tog
leetcode#21 Merge Two Sorted Lists
solution ould pub eth linked public and urn ini Merge two sorted linked lists and return it as a new list. The new list should be made by
LeetCode#21: Merge Two Sorted Lists
Description 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
leetcode:(21) Merge Two Sorted Lists(java)
package LeetCode_LinkedList; /** * 題目: * Merge two sorted linked lists and return it as a new list. * The new list should be made by spl
21. 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. Exampl
#21 Merge Two Sorted Lists
1 /** 2 * Definition for singly-linked list. 3 * public class ListNode { 4 * int val; 5 * ListNode next; 6 * ListNode(int x) {
[leetcode] 21. Merge Two Sorted Lists (Easy)
合併連結串列 Runtime: 4 ms, faster than 100.00% of C++ online submissions for Merge Two Sorted Lists. class Solution { public: ListNode *mergeTwoList
[Leetcode]21. Merge Two Sorted Lists
合併兩個排序好的列表,遞迴演算法pass /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x)
【LeetCode】21. Merge Two Sorted Lists - Java實現
文章目錄 1. 題目描述: 2. 思路分析: 3. Java程式碼: 1. 題目描述: Merge two sorted linked lists and return it as a new list. The new list
21 Merge Two Sorted Lists
水題 class Solution { public: ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) { if (l1 == NULL&&l2 == NULL)return l1; ListNode *f
C# 寫 LeetCode easy #21 Merge Two Sorted Lists
21、 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 fi
LeetCode 21: 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 fir
Leetcode_Linked_List --21. Merge Two Sorted Lists [easy]
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
[LeetCode&Python] Problem 21. 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. Example: In
LeetCode - 21. 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.