From 727b3871e1547f5abfec358bf352425f61eb7b5b Mon Sep 17 00:00:00 2001 From: ratheroo Date: Sat, 20 Apr 2019 23:54:04 +0800 Subject: [PATCH 1/2] Create swapPairs.c --- Week_01/id_114/swapPairs.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Week_01/id_114/swapPairs.c diff --git a/Week_01/id_114/swapPairs.c b/Week_01/id_114/swapPairs.c new file mode 100644 index 00000000..ab080346 --- /dev/null +++ b/Week_01/id_114/swapPairs.c @@ -0,0 +1,24 @@ +/** + * Definition for singly-linked list. + * struct ListNode { + * int val; + * struct ListNode *next; + * }; + */ +struct ListNode* swapPairs(struct ListNode* head) { + struct ListNode* temp; + + if(!head){ + return NULL; + } + if(!head->next){ + return head; + } + + temp = (struct ListNode*)malloc(sizeof(struct ListNode)); + + temp = head->next; + head->next=swapPairs(temp->next); + temp->next=head; + return temp; +} From a33bcbccccb8508c0e7df623184c2f8e38ca195c Mon Sep 17 00:00:00 2001 From: ratheroo Date: Sat, 20 Apr 2019 23:54:57 +0800 Subject: [PATCH 2/2] Create mergeTwoLists.c --- Week_01/id_114/mergeTwoLists.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Week_01/id_114/mergeTwoLists.c diff --git a/Week_01/id_114/mergeTwoLists.c b/Week_01/id_114/mergeTwoLists.c new file mode 100644 index 00000000..10504f2f --- /dev/null +++ b/Week_01/id_114/mergeTwoLists.c @@ -0,0 +1,32 @@ +/** + * Definition for singly-linked list. + * struct ListNode { + * int val; + * struct ListNode *next; + * }; + */ +struct ListNode* mergeTwoLists(struct ListNode* l1, struct ListNode* l2) { + struct ListNode* head; + struct ListNode* res; + res = (struct ListNode*)malloc(sizeof(struct ListNode)); + head = res; + + while(l1 && l2){ + if(l1->val < l2->val){ + res->next = l1; + l1 = l1->next; + }else{ + res->next = l2; + l2 = l2->next; + } + res = res->next; + } + + if(l1){ + res->next = l1; + }else{ + res->next = l2; + } + + return head->next; +}