Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- http://leetcode.com/onlinejudge#question_83
- 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.
- */
- class Solution {
- public:
- ListNode *deleteDuplicates(ListNode *head) {
- ListNode * a = head, *b;
- for(; a != NULL; a = a->next)
- {
- while(NULL != (b = a->next) && a->val == b->val)
- {
- a->next = b->next;
- }
- }
- return head;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment