class Solution {
public:
ListNode* deleteDuplicates(ListNode* head) {
ListNode dummy(-1), *pre = &dummy, *iter;
dummy.next = head;
while (pre && pre->next) {
if (pre->next->next && pre->next->next->val == pre->next->val) {
iter = pre->next;
while (iter && iter->val == pre->next->val)
iter = iter->next;
pre->next = iter;
} else {
pre = pre->next;
}
}
return dummy.next;
}
};
Remove Duplicates from Sorted List II simple and fast
最新推荐文章于 2023-10-09 02:02:27 发布