标签:
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
.
[Solution]
1 ListNode *deleteDuplicates(ListNode *head) 2 { 3 ListNode *p = head, *q; 4 5 if (head == NULL) 6 return head; 7 8 while (p->next != NULL) 9 { 10 q = p->next; 11 if (p->val == q->val) 12 p->next = q->next; 13 else 14 p = p->next; 15 } 16 17 return head; 18 }
leetcode 83. Remove Duplicates from Sorted List
标签:
原文地址:http://www.cnblogs.com/ym65536/p/4296880.html