Given a sorted linked list, delete all duplicates such that each element appear only once.
For example,
Given 1->1->2, return 1->2.
Given 1->1->2->3->3, return 1->2->3.
容易
ListNode *deleteDuplicates(ListNode *head) {
ListNode *next = NULL;
ListNode *curr = head;
while (curr) {
if (curr->next == NULL) {
return head;
}
next = curr->next;
if (curr->val == next->val) {
curr->next = next->next;
continue;
}
curr = curr->next;
}
return head;
}
LeetCode83——Remove Duplicates from Sorted List
原文地址:http://blog.csdn.net/booirror/article/details/43734515