From ac8e7bb848091a7849fb00675af537b981743719 Mon Sep 17 00:00:00 2001 From: Manuel Pineda Date: Tue, 5 Jan 2021 12:08:55 +0100 Subject: [PATCH] Add 05.cc --- solved/LeetCode/Challenges/2020/January/05.cc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 solved/LeetCode/Challenges/2020/January/05.cc diff --git a/solved/LeetCode/Challenges/2020/January/05.cc b/solved/LeetCode/Challenges/2020/January/05.cc new file mode 100644 index 00000000..022ea9ea --- /dev/null +++ b/solved/LeetCode/Challenges/2020/January/05.cc @@ -0,0 +1,17 @@ +class Solution { +public: + ListNode* deleteDuplicates(ListNode* head) { + if ((head == nullptr) || (head->next == nullptr)) { + return head; + } + int t = head->next->val; + if (head->val != t) { + head->next = deleteDuplicates(head->next); + return head; + } + while (head != nullptr && head->val == t) { + head = head->next; + } + return deleteDuplicates(head); + } +};