/**
* 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
if(!head) return NULL;
ListNode *p = head;
int cur = p->val;
ListNode *q;
while(p->next){
q = p->next;
if(q->val != cur){
cur = q->val;
p = p->next;
}else{
p->next = q->next;
delete q;
}
}
return head;
}
};
[leetcode]Remove Duplicates from Sorted List
最新推荐文章于 2021-10-31 21:26:34 发布