problem
Remove Duplicates from Sorted List
考察的是链表的基本用法。
code
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode* deleteDuplicates(ListNode* head) { ListNode* cur = head; while(cur && cur->next)//null is error. { if(cur->val == cur->next->val) cur->next = cur->next->next; else cur = cur->next; // } return head; } };
参考
1. Remove Duplicates from Sorted List;
完