/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* removeDuplicateNodes(ListNode* head) {
set<int> mySet;
ListNode* p = head;
ListNode*pre;
while(p){
if(mySet.insert(p->val).second == false){
p = p->next;
pre->next = pre->next->next;
}else{
pre = p;
p = p->next;
}
}
return head;
}
};
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)