From ba4f7f67618630be34746d2846221796718482fc Mon Sep 17 00:00:00 2001 From: Amanda <3365485465@qq.com> Date: Sun, 19 May 2019 14:38:03 +0800 Subject: [PATCH 1/2] Create LeetCode_83_056.cpp --- Week_01/id_56/LeetCode_83_056.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Week_01/id_56/LeetCode_83_056.cpp diff --git a/Week_01/id_56/LeetCode_83_056.cpp b/Week_01/id_56/LeetCode_83_056.cpp new file mode 100644 index 00000000..7a45f07a --- /dev/null +++ b/Week_01/id_56/LeetCode_83_056.cpp @@ -0,0 +1,17 @@ +class Solution { +public: + ListNode* deleteDuplicates(ListNode* head) { + if ((head == nullptr) || (head->next == nullptr)) return head; + ListNode* node = head; + ListNode* nextNode = node->next; + while (nextNode != nullptr) { + if (nextNode->val == node->val) { + node->next = nextNode->next; + nextNode->next = nullptr; + } else node = nextNode; + nextNode = node->next; + } + + return head; + } +}; From f7b56e9468cbf906df118660678b56580a7c39c8 Mon Sep 17 00:00:00 2001 From: Amanda <3365485465@qq.com> Date: Sun, 19 May 2019 14:41:02 +0800 Subject: [PATCH 2/2] Create LeetCode_21_056.cpp --- Week_01/id_56/LeetCode_21_056.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Week_01/id_56/LeetCode_21_056.cpp diff --git a/Week_01/id_56/LeetCode_21_056.cpp b/Week_01/id_56/LeetCode_21_056.cpp new file mode 100644 index 00000000..d06c5424 --- /dev/null +++ b/Week_01/id_56/LeetCode_21_056.cpp @@ -0,0 +1,22 @@ +public class Solution { + public ListNode mergeTwoLists(ListNode l1, ListNode l2) { + if(l1 == null && l2 == null) + return null; + if(l1 == null) + return l2; + if(l2 == null) + return l1; + ListNode head = null; + if(l1.val > l2.val) + { + head = l2; + head.next = mergeTwoLists(l1, l2.next); + } + else + { + head = l1; + head.next = mergeTwoLists(l1.next, l2); + } + return head; + } + }