【leetcode】Remove Duplicates from Sorted List
来源:互联网 发布:php ll 和 优先级 编辑:程序博客网 时间:2024/06/05 22:25
/** * 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; }};
- Remove Duplicates from Sorted List :from LeetCode
- Leetcode - List - Remove Duplicates from Sorted List
- [leetcode][list] Remove Duplicates from Sorted List
- [leetcode][list] Remove Duplicates from Sorted List
- LeetCode: Remove Duplicates from Sorted List
- LeetCode: Remove Duplicates from Sorted List II
- [Leetcode] Remove Duplicates from Sorted List
- [Leetcode] Remove Duplicates from Sorted List II
- LeetCode: Remove Duplicates from Sorted List
- LeetCode: Remove Duplicates from Sorted List II
- [Leetcode] Remove Duplicates from Sorted List II
- leetcode 37: Remove Duplicates from Sorted List
- [leetcode] 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
- [leetcode] Remove Duplicates from Sorted List II
- [LeetCode]Remove Duplicates from Sorted List
- Java interrupt
- C#中int与Int32关系揭秘
- Block SSH Server Attacks (Brute Force Attacks) Using DenyHosts
- toj2273 Making Change
- spring security3.x学习(19)_tomcat的SSL
- 【leetcode】Remove Duplicates from Sorted List
- 冯·诺依曼计算机的特点
- C#中HashTable的用法
- spring security3.x学习(20)_初探authorize标签和第四个例子
- android中字符串资源的使用
- 25 Useful Basic Commands of APT-GET and APT-CACHE for Package Management
- UVA 357 Let Me Count The Ways dp水题跟
- java的简单程序
- 保护眼睛——设置WIN7和XP 窗体、Chrome、IE网页背景颜色(zz)