ListNode* dummy = new ListNode(0); //必须要加上 new ListNode(0); 否则有错误。 dummy->next = head; head = dummy; while(head->next && head->next->next) { if(head->next->val == head->next->next->val) { int value = head->next->val; while(head->next && head->next->val == value) { head->next = head->next->next; } } else { head = head->next; } } return dummy->next;
有时候应换一种思路。
转载于:https://www.cnblogs.com/yanqi110/p/5003795.html