LeetCode 83. Remove Duplicates from Sorted List

原创 2018年04月17日 21:24:29

问题描述

  • Given a sorted linked list, delete all duplicates such that each element appear only once.
    For example,
    Given 1->1->2, return 1->2.
    Given 1->1->2->3->3, return 1->2->3.
  • 地址

问题分析

  • 只保留重复中的第一个即可

代码实现

/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) { val = x; }
 * }
 */
class Solution {
    public ListNode deleteDuplicates(ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }
        ListNode preNode = head;
        ListNode curNode = null;
        while (preNode != null) {
            curNode = preNode.next;
            while (curNode != null && curNode.val == preNode.val){
                curNode = curNode.next;
            }
            preNode.next = curNode;
            preNode = curNode;
        }
        return head;
    }
}
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zjxxyz123/article/details/79981103

Leetcode_83_Remove Duplicates from Sorted List

本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/41728739 Given a sorted linked...
  • pistolove
  • pistolove
  • 2014-12-04 19:20:34
  • 1557

LeetCode(83)Remove Duplicates from Sorted List

题目如下: Given a sorted linked list, delete all duplicates such that each element appear only once. For...
  • feliciafay
  • feliciafay
  • 2014-01-10 08:06:49
  • 2869

LeetCode 83 — Remove Duplicates from Sorted List(C++ Java Python)

题目:http://oj.leetcode.com/problems/remove-duplicates-from-sorted-list/ Given a sorted linked list, ...
  • dragon_dream
  • dragon_dream
  • 2014-04-01 19:43:21
  • 2535

[leetcode]Remove Duplicates from Sorted List (删除有序节点的值重复的节点 C语言)

Remove Duplicates from Sorted List Given a sorted linked list, delete all duplicates such that eac...
  • sanmao0816
  • sanmao0816
  • 2015-03-28 18:17:40
  • 651

83. Remove Duplicates from Sorted List(python)

Given a sorted linked list, delete all duplicates such that each element appear only once. For exam...
  • qq_28119401
  • qq_28119401
  • 2016-09-18 21:34:35
  • 317

83. Remove Duplicates from Sorted List [easy] (Python)

题目链接https://leetcode.com/problems/remove-duplicates-from-sorted-list/题目原文 Given a sorted linked li...
  • coder_orz
  • coder_orz
  • 2016-05-26 12:25:58
  • 1273

82. Remove Duplicates from Sorted List II Leetcode Python

Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb...
  • hyperbolechi
  • hyperbolechi
  • 2015-02-05 11:48:11
  • 1013

Remove Duplicates from Sorted List -- LeetCode

原题链接: http://oj.leetcode.com/problems/remove-duplicates-from-sorted-list/  这是一道比较简单的链表操作的题目,要求是删去有序...
  • linhuanmars
  • linhuanmars
  • 2014-04-23 11:25:06
  • 8930

leecode 解题总结:83. Remove Duplicates from Sorted List

#include #include #include using namespace std; /* 问题: Given a sorted linked list, delete all dup...
  • qingyuanluofeng
  • qingyuanluofeng
  • 2017-02-13 00:02:10
  • 133

LeetCode 83 -Remove Duplicates from Sorted List ( JAVA )

Given a sorted linked list, delete all duplicates such that each element appear only once. For ex...
  • UckyK
  • UckyK
  • 2016-04-15 16:57:35
  • 351
收藏助手
不良信息举报
您举报文章:LeetCode 83. Remove Duplicates from Sorted List
举报原因:
原因补充:

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