标签:while bsp turn pre rgb 重复元素 重复 lse let
没啥太难的思路,代码如下:
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : val(x), next(nullptr) {} * ListNode(int x, ListNode *next) : val(x), next(next) {} * }; */ class Solution { public: ListNode* deleteDuplicates(ListNode* head) { ListNode* temp1 = new ListNode(0,head); ListNode* temp = temp1; ListNode* temp2 = head; if(!head || !head->next) return head; while(temp2 && temp2->next) { if(temp2->val == temp2->next->val) { while(temp2->next && temp2->val == temp2->next->val) temp2 = temp2->next; temp2 = temp2->next; temp1->next = temp2; } else { temp1 = temp2; temp2 = temp2->next; } } return temp->next; } };
标签:while bsp turn pre rgb 重复元素 重复 lse let
原文地址:https://www.cnblogs.com/zhaohhhh/p/14403716.html