leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE |

commit796ec663cba5857c88c1577eea5d8c364c811188
parent5f566a67e1294713dec897cecba63e54503c07e6
authorDimitrije Dobrota <mail@dimitrijedobrota.com>
dateSun, 5 Feb 2023 12:08:19 +0100

Algorithm II: Day 3

Diffstat:
AProblems/0082.cpp|+++++++++++++++++
MREADME.md|+

2 files changed, 18 insertions(+), 0 deletions(-)


diff --git a/Problems/0082.cpp b/Problems/0082.cpp

@@ -0,0 +1,17 @@

class Solution {
public:
ListNode *deleteDuplicates(ListNode *head) {
ListNode top(-200, head);
for (ListNode *p = &top, *c = head; c && c->next; c = c->next) {
if (c->val == c->next->val) {
while (c && c->next && c->val == c->next->val) c = c->next;
p->next = c->next;
if (!c) break;
} else
p = p->next;
}
return top.next;
}
};

diff --git a/README.md b/README.md

@@ -66,6 +66,7 @@ for solving problems.

| 0074 | Medium | [Search a 2D Matrix](Problems/0074.cpp) |
| 0075 | Medium | [Sort Colors](Problems/0075.cpp) |
| 0077 | Medium | [Combinations](Problems/0077.cpp) |
| 0082 | Medium | [Remove Duplicates from Sorted List II](Problems/0082.cpp) |
| 0083 | Easy | [Remove Duplicates from Sorted List](Problems/0083.cpp) |
| 0084 | Hard | [Largest Rectangle in Histogram](Problems/0084.cpp) |
| 0088 | Easy | [Merge Sorted Array](Problems/0088.cpp) |