【leetcode】Remove Duplicates from Sorted List
2013-09-21 20:58
375 查看
/** * 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) { // Start typing your C/C++ solution below // DO NOT write int main() function if(head==NULL||head->next==NULL) return head; ListNode *dummy = new ListNode(0); dummy->next=head; ListNode *pre=dummy; ListNode *cur=dummy->next; bool needDelete=false; while(cur!=NULL&&cur->next!=NULL) { if(cur->val==cur->next->val) needDelete=true; else { if(needDelete) { pre->next=cur;//dif from [Remove Duplicates from Sorted List II] pre=cur;//dif from [Remove Duplicates from Sorted List II] needDelete=false; } else { pre=cur; } } cur=cur->next; } if(needDelete) pre->next=cur;//dif from [Remove Duplicates from Sorted List II] return dummy->next; } };
相关文章推荐
- leetcode Remove Duplicates from Sorted List II
- 【LeetCode with Python】 Remove Duplicates from Sorted List II
- leetcode之Remove Duplicates from Sorted List II
- LeetCode: Remove Duplicates from Sorted List II
- leetcode第83题-Remove Duplicates from Sorted List
- LeetCode 26, 80, 81, 82, . Remove Duplicates from Sorted Array/ List i, ii
- [LeetCode] Remove Duplicates from Sorted List II
- leetcode笔记--Remove Duplicates from Sorted List II
- leetcode(83)—— 删除已排序链表重复元素(Remove Duplicates from Sorted List)
- [LeetCode]Remove Duplicates from Sorted List
- LeetCode[Linked List]: Remove Duplicates from Sorted List II
- Leetcode-Remove Duplicates from Sorted List II(二级指针)
- leetcode -- Remove Duplicates from Sorted List II
- Remove Duplicates from Sorted List II 链表移除重复值@LeetCode
- [leetcode]83 Remove Duplicates from Sorted List
- Leetcode:Remove Duplicates from Sorted List II
- LeetCode 082 Remove Duplicates from Sorted List II
- LEETCODE: Remove Duplicates from Sorted List II
- LeetCode之Remove Duplicates from Sorted List
- [leetcode]Remove Duplicates from Sorted List (删除有序节点的值重复的节点 C语言)