Remove Duplicates from Sorted List

原创 2015年07月07日 23:57:52

题目描述

Given a sorted linked list, delete all duplicates such that each element appear only once.

Given 1->1->2, return 1->2.
Given 1->1->2->3->3, return 1->2->3.

链接地址

http://www.lintcode.com/en/problem/remove-duplicates-from-sorted-list/

解法

     ListNode *deleteDuplicates(ListNode *head) {
        // write your code here
        if (head == NULL) {
            return head;
        }
        ListNode *dummyNode = head;
       // dummyNode = head;
        while (dummyNode != NULL) {
            if (dummyNode->next != NULL && dummyNode->val == dummyNode->next->val) {
                ListNode *temp = dummyNode->next;
                dummyNode->next = dummyNode ->next->next;
                delete temp;
            } else {
                dummyNode = dummyNode->next;
            }
        }
        return head;
    }

相关文章推荐

LeetCode :: Remove Duplicates from Sorted List[详细分析]

Given a sorted linked list, delete all duplicates such that each element appear only once. For ex...

Remove Duplicates from Sorted List--LeetCode

题目: Given a sorted linked list, delete all duplicates such that each element appear only once. Fo...

LeetCode82:Remove Duplicates from Sorted List II

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

Remove Duplicates from Sorted List II--LeetCode

题目: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinc...

Remove Duplicates from Sorted List I,II

Remove Duplicates from Sorted List   Given a sorted linked list, delete all duplicates such that ea...

[LeetCode] Remove Duplicates from Sorted List II

给定一个已经排序的单链表,删除所有有相同数字的节点,只留下原始链表中的不同数字。...

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

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

[83] Remove Duplicates from Sorted List

单向排好序的链表删除重复元素
  • camlot_
  • camlot_
  • 2016年06月28日 09:48
  • 151

LeetCode - 82. Remove Duplicates from Sorted List II

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

和大神们学习每天一题(leetcode)-Remove Duplicates from Sorted List

Given a sorted linked list, delete all duplicates such that each element appear only once. For ex...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Remove Duplicates from Sorted List
举报原因:
原因补充:

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