http://oj.leetcode.com/problems/remove-duplicates-from-sorted-list/
/**
* 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) return head;
while(head->next!=NULL&&head->val==head->next->val){
head->next=head->next->next;
}
deleteDuplicates(head->next);
return head;
}
};
本文介绍了解决删除排序链表中重复元素的问题,通过迭代遍历链表并删除重复节点,确保链表中每个元素只出现一次。
279

被折叠的 条评论
为什么被折叠?



