Remove Duplicates from Sorted List
Input: 1->1->2
Output: 1->2Input: 1->1->2->3->3
Output: 1->2->3Basic Idea:
C++ Code
Recursion
class Solution {
public:
ListNode* deleteDuplicates(ListNode* head) {
if (head == nullptr || head->next == nullptr) return head;
head->next = deleteDuplicates(head->next);
return head->val == head->next->val ? head->next : head;
}
};