/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode *deleteDuplicates(ListNode *head) {
if(head == NULL)
return head;
ListNode *head1 = head;
int pre = head->val;
while(head->next != NULL)
{
ListNode *temp = head;
head = head->next;
if(head->val == pre)
{
temp->next = temp->next->next;
head = temp;
}
else
pre = head->val;
}
return head1;
}
};
问题比较简单,保存相似节点的第一个值,然后遍历链表,若后一节点与当前节点值
相同则删除此节点,若不是则跟新这个标准值