排序过的链表,顺序遍历就ok
时间复杂度:O(N)
C++代码:
class Solution {
public:
ListNode* deleteDuplicates(ListNode* head) {
ListNode* record = head;
while(head != nullptr && head->next != nullptr)
{
if(head->val == head->next->val)
{
head->next = head->next->next;
}
else
{
head = head->next;
}
}
return record;
}
};