/**
* 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) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
ListNode* root = NULL;
ListNode** ppNext = &root;
while (head)
{
if (head->next == NULL || head->next->val != head->val)
{
*ppNext = head;
ppNext = &(head->next);
head = head->next;
}
else
{
int val = head->val;
do
{
head = head->next;
} while (head != NULL && head->val == val);
}
}
*ppNext = NULL;
return root;
}
};
[Leetcode] Remove Duplicates from Sorted List II
最新推荐文章于 2022-04-03 22:46:44 发布