
- struct ListNode* deleteDuplicates(struct ListNode* head) {
- if(head==NULL||head->next==NULL)
- {
- return head;
- }
- struct ListNode*cur=head;
- while(cur->next)
- {
- if(cur->val==cur->next->val)
- {
- cur->next=cur->next->next;
- }
- else
- {
- cur=cur->next;
- }
- }
- return head;
- }
注意如果判断成功则不能移动当前节点到下一个节点,这样会存在跳节点的情况