标签:
很简单的一题,需要注意的是如果某结点重复了记得将其删除。
ListNode *deleteDuplicates(ListNode *head) { if (head == nullptr) return nullptr; ListNode *prev = head; for (ListNode *cur = head->next; cur != nullptr; cur = cur->next) { if (cur->val == prev->val) { prev->next = cur->next; delete cur; } else prev->next = cur; } }
leetcode 之Remove Duplicates from Sorted List(16)
标签:
原文地址:http://www.cnblogs.com/573177885qq/p/5505460.html