Given a sorted linked list, delete all duplicates such that each element appear only once.
For example,
Given1->1->2
, return 1->2
. Given 1->1->2->3->3
, return 1->2->3
. class Solution {public: ListNode *deleteDuplicates(ListNode *head) { // Start typing your C/C++ solution below // DO NOT write int main() function ListNode dy_node(0), *q = &dy_node; ListNode de_node(0), *q1 = &de_node; int last = INT_MAX; for(ListNode *p = head; p; p = p->next){ if (last != p->val){ q = q->next = p; last = p->val; }else{ q1 = q1->next = p; } } q->next = NULL; q1->next = NULL; /* ListNode *p = de_node.next; while(p){ ListNode *temp = p->next; delete p; p = temp; }*/ return dy_node.next; }};