/** * 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) { if(head == NULL)return head; ListNode* move; move = head; while(move->next != NULL){ if(move->val == move->next->val){ move->next = move->next->next; } else{ move = move->next; } } return head; } };
水题