草稿暂存
来源:互联网 发布:怎么把数据导入matlab 编辑:程序博客网 时间:2024/04/28 00:59
class Solution {public: ListNode *deleteDuplicates(ListNode *head) { if (head == NULL) return NULL; bool isDup; ListNode *pos = head, *next_pos = head->next; if (next_pos == NULL) return head; ListNode *pre_pos = new ListNode(0); ListNode *new_head = pre_pos; pre_pos->next = head; while (next_pos != NULL) { isDup = false; while (next_pos != NULL && pos->val == next_pos->val) { isDup = true; next_pos = next_pos->next; } if (isDup) { pre_pos->next = next_pos; pos = next_pos; } else { pre_pos = pre_pos->next; pos = pos->next; } next_pos = next_pos->next; } return new_head->next; }};
0 0