83.Remove Duplicates from Sorted List
示例 1:
输入: 1->1->2
输出: 1->2
示例 2:
输入: 1->1->2->3->3
输出: 1->2->3/**
* 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) return head;
ListNode* root=head;
ListNode* fast=head->next;
while(fast)
{
if(root->val == fast->val)
{
root->next = fast->next;
fast=fast->next;
}
else
{
root=root->next;
fast=fast->next;
}
}
return head;
}
};Last updated