1 /**
2 * Definition of ListNode
3 * class ListNode {
4 * public:
5 * int val;
6 * ListNode *next;
7 * ListNode(int val) {
8 * this->val = val;
9 * this->next = NULL;
10 * }
11 * }
12 */
13 class Solution {
14 public:
15 /**
16 * @param head: The first node of linked list.
17 * @return: head node
18 */
19 ListNode *deleteDuplicates(ListNode *head) {
20 // write your code here
21 if(NULL == head)
22 return NULL;
23
24 ListNode *p1=head, *p2=head->next;
25
26 if(NULL == p2)
27 return head;
28
29 while(p2 != NULL) {
30 if(p1->val == p2->val) {
31 p1->next = p2->next;
32 p2 = p2->next;
33 }
34 else {
35 p1 = p1->next;
36 p2 = p2->next;
37 }
38 }
39 return head;
40 }
41 };