您的位置:首页 > 其它

leetcode之Remove Duplicates from Sorted List

2013-09-17 20:12 253 查看
/**

* 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==NULL||head->next==NULL) {

return head;

}

ListNode* phead=head;

while(phead->next) {

if (phead->val==phead->next->val) {

ListNode* p =phead->next;

phead->next=p->next;

p->next=NULL;

delete p;

p=0;

} else {

phead=phead->next;

}

}

return head;

}

};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: