/**
* 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) {
ListNode* curr=head;
while(curr&&curr->next)
{
if(curr->val==curr->next->val)
{
ListNode* temp=curr->next;
curr->next=curr->next->next;
delete temp;
}
else
curr=curr->next;
}
return head;
}
};
leetcode 83: Remove Duplicates from Sorted List
最新推荐文章于 2024-11-10 15:36:20 发布