22. Remove duplicates from an unsorted linked list
My Approach
Time and Auxiliary Space Complexity
Code (C++)
class Solution {
public:
Node *removeDuplicates(Node *head) {
unordered_map<int, bool> isDup;
Node* itr = head;
Node* skipItr;
while (itr) {
isDup[itr->data] = true;
skipItr = itr->next;
while (skipItr && isDup.find(skipItr->data) != isDup.end())
skipItr = skipItr->next;
itr->next = skipItr;
itr = skipItr;
}
return head;
}
};Contribution and Support
Last updated