Skip to content

Commit

Permalink
Create 83-Remove-Duplicates-from-Sorted-List.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
nehalalifayed authored Oct 12, 2022
1 parent 991bcf5 commit 678a5e7
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cpp/83-Remove-Duplicates-from-Sorted-List.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Time Complexity is O(N).
// Space Complexity is O(1).

class Solution {
public:
ListNode* deleteDuplicates(ListNode* head) {
ListNode * fast = head;
ListNode * slow = head;

while(slow != NULL)
{
while(fast != NULL && slow->val == fast->val)
fast = fast -> next;

slow->next = fast;
slow = slow -> next;
}

return head;

}
};

0 comments on commit 678a5e7

Please sign in to comment.