LeetCode 83. Remove Duplicates from Sorted List Posted on 2021-03-26 Edited on 2024-11-24 In LeetCode IterationRecursion12345678910111213class Solution {public: ListNode* deleteDuplicates(ListNode* head) { if (!head) return head; ListNode* curr = head; while (curr->next) if (curr->val == curr->next->val) curr->next = curr->next->next; else curr = curr->next; return head; }};1234567891011class Solution {public: ListNode* deleteDuplicates(ListNode* head) { if (!head || !head->next) return head; while (head->next && head->next->val == head->val) head = head->next; head->next = deleteDuplicates(head->next); return head; }};