/**
* 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 NULL;
if(head-> next == NULL)
return head;
ListNode* lp = head, *lm = NULL;
int n;
while(lp->next->next != NULL){
if(lp->val == lp->next->val){
lp->next = lp->next->next;
}
else{
lp = lp->next;
}
}
if(lp->val == lp->next->val){
lp->next = NULL;
}
return head;
}
};
leetcode-83-remove duplicates from sorted lists
最新推荐文章于 2021-10-07 22:18:49 发布