【leetcode】Remove Duplicates from Sorted List II
来源:互联网 发布:网络诈骗教育考试题库 编辑:程序博客网 时间:2024/04/28 08:19
/** * 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==true) { pre->next=cur->next;//will change the structure of the list needDelete=false; } else pre=cur;//will not change the structure of the list } cur=cur->next; } if(needDelete) pre->next=NULL;//will change the structure of the list return dummy->next; }};
- LeetCode: Remove Duplicates from Sorted List II
- [Leetcode] Remove Duplicates from Sorted List II
- LeetCode: Remove Duplicates from Sorted List II
- [Leetcode] Remove Duplicates from Sorted List II
- [leetcode] Remove Duplicates from Sorted List II
- [LeetCode] Remove Duplicates from Sorted List II
- [leetcode] Remove Duplicates from Sorted List II
- [LeetCode]Remove Duplicates from Sorted List II
- [leetcode]Remove Duplicates from Sorted List II
- LeetCode-Remove Duplicates from Sorted List II
- [leetcode] Remove Duplicates from Sorted List II
- LeetCode - Remove Duplicates from Sorted List II
- LeetCode | Remove Duplicates from Sorted List II
- LeetCode:Remove Duplicates from Sorted List II
- 【leetcode】Remove Duplicates from Sorted List II
- Leetcode: Remove Duplicates from Sorted List II
- leetcode Remove Duplicates from Sorted List II
- [LeetCode] Remove Duplicates from Sorted List II
- Android学习之创建和使用数据库
- zigbee zcl规范及其协议栈实现2
- 我那之大手机导航刷卡机
- Two Methods of Finding the sum of 1! + 2! +3! + 4! +...+ 20!
- zigbee zcl规范及其协议栈实现3 读取服务器端属性值
- 【leetcode】Remove Duplicates from Sorted List II
- COM
- uva 152 Tree's a Crowd
- 待解决问题
- IO:包装类PrintStream的使用
- mvc示例项目之一----开篇及ORM生成实体
- 直接拿来用!超实用的Java数组技巧攻略
- 集群时间同步
- Details of GRUB on the PC