【LeetCode】82. Remove Duplicates from Sorted List II

原创 2016年05月31日 20:19:58

思路

很简单的一道题,思路也没什么特别的,就是设置一个prehead节点


代码

 ListNode* deleteDuplicates(ListNode* head) {
        ListNode nHead(0);
        ListNode* phead = &nHead;
        ListNode* tmp = &nHead;
        bool flag;
        while(head){
            flag=true;
            if (!head->next){
                tmp->next=head;
                tmp=tmp->next;
            }
            else{
                while (head->next && head->val==head->next->val){
                    head = head->next;
                    flag=false;
                }
                if (flag){
                    tmp->next=head;
                    tmp=tmp->next;
                }
            }
            head=head->next;
        }
        tmp->next=NULL;
        return phead->next;
    }

相关文章推荐

LeetCode82:Remove Duplicates from Sorted List II

Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct num...

【一天一道LeetCode】#82. Remove Duplicates from Sorted List II

一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder‘s Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目...

LeetCode - 82. Remove Duplicates from Sorted List II

这一道题目主要是链表的操作,一开始因为情况比较复杂,把自己绕晕了,所以没想到这道题目的解法,后来看了答案才觉得自己解起来确实很难解出。这道题目对于链表的操作比较复杂,所要考虑的情况也很多,最大的一个技...

leetcode_82_Remove Duplicates from Sorted List II

思路: 大致思路就是,遍历链表找出重复元素的子列并删除重复元素子列,当然,第一个元素开始有重复元素的话比较特种,需要特殊考虑。删除子列的过程稍微有点绕,题目倒是不难理解。...

[leetcode 82]Remove Duplicates from Sorted List II

Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb...

LeetCode 82. Remove Duplicates from Sorted List II pre指针,首元素的处理

题目 题意 注意 思路 代码 结果题目 Given a sorted linked list, delete all nodes that have duplicate numbers, leav...

[leetcode] 82. Remove Duplicates from Sorted List II

Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb...

[LeetCode]82.Remove Duplicates from Sorted List II

【题目】 Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distin...

leetcode || 82、Remove Duplicates from Sorted List II

problem: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving onl...

【leetcode c++】82 Remove Duplicates from Sorted List II

Remove Duplicates from Sorted List II Given a sorted linked list, delete allnodes that have duplica...
  • hqq39
  • hqq39
  • 2015年07月17日 23:16
  • 283
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:【LeetCode】82. Remove Duplicates from Sorted List II
举报原因:
原因补充:

(最多只允许输入30个字)