We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 62ddf67 commit cd61f4cCopy full SHA for cd61f4c
solution/021.Merge Two Sorted Lists/Solution.cpp
@@ -0,0 +1,37 @@
1
+/**
2
+ * Definition for singly-linked list.
3
+ * struct ListNode {
4
+ * int val;
5
+ * ListNode *next;
6
+ * ListNode(int x) : val(x), next(NULL) {}
7
+ * };
8
+ */
9
+class Solution {
10
+public:
11
+ ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) {
12
+ ListNode *a1=new ListNode(0);
13
+ ListNode *head=a1;
14
+ while(l1!=NULL&&l2!=NULL)
15
+ {
16
+ if(l1->val<l2->val)
17
18
+ a1->next=l1;
19
+ l1=l1->next;
20
+ a1=a1->next;
21
+ }
22
+ else
23
24
+ a1->next=l2;
25
+ l2=l2->next;
26
27
28
29
+ if(l1==NULL)
30
31
+ if(l2==NULL)
32
33
+ return head->next;
34
+
35
36
37
+};
0 commit comments