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.

设置2个指针,cur 和next。

当cur的值与next的值相等时,cur.next= next.next   更新next = next.next;

当cur的值与next的值不等时,cur = next   更新next = next.next;

 public class Solution {
public ListNode deleteDuplicates(ListNode head) {
if(head == null ||head.next == null) return head;
ListNode cur = head;
ListNode next = head.next;
while(next != null){
if(cur.val == next.val)
cur.next = next.next;
else cur = next;
next = next.next;
}
return head;
}
 

[LeetCode]83. Remove Duplicates from Sorted List(排序链表去重)的更多相关文章

  1. [leetcode]83. Remove Duplicates from Sorted List有序链表去重

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

  2. [LeetCode] 83. Remove Duplicates from Sorted List 移除有序链表中的重复项

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

  3. [LeetCode] 83. Remove Duplicates from Sorted List ☆(从有序链表中删除重复项)

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

  4. leetCode 83.Remove Duplicates from Sorted List(删除排序链表的反复) 解题思路和方法

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

  5. LeetCode 83. Remove Duplicates from Sorted List (从有序链表中去除重复项)

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

  6. Java [Leetcode 83]Remove Duplicates from Sorted List

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

  7. [LeetCode] 83. Remove Duplicates from Sorted List_Easy tag: Linked List

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

  8. Leetcode 83 Remove Duplicates from Sorted List 链表

    就是将链表中的重复元素去除 我的方法很简单就是如果链表的前后元素相同的话,将后一个元素删除 /** * Definition for singly-linked list. * struct List ...

  9. LeetCode 83. Remove Duplicates from Sorted List(从有序链表中删除重复节点)

    题意:从有序链表中删除重复节点. /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode ...

随机推荐

  1. Extjs不错的博客

    http://www.cnblogs.com/fangsui/category/372751.html http://www.cnblogs.com/WangJinYang/tag/EXT.NET/ ...

  2. swift - UIAlertView 的用法

    1,创建一个alertview,并带有“确定”和“取消”两个按钮 (注:在这里使用alertview,会报警告,那是因为从ios 8 以后,建议使用UIAlertviewController) //警 ...

  3. Oracle应用技术精华教程:管理还原段

    管理还原段 在oracle 9i 之后提供了两种方法来管理还原数据 自动的还原数据管理:oracle 自动管理还原段的创建.分配和优化 手动的还原数据管理:oracle 手动管理还原段的创建.分配和优 ...

  4. linux下jdk,tomcat的安装

    一.安装jdk 1.jdk下载地址: http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.ht ...

  5. lua知识点整理

    1. lua全局环境和局部环境 local cf = loadstring(" local i=0 i=i+1 print(i) ") --从后面两个输出我们可以看出,生成的函数的 ...

  6. Linux命令之type - 显示命令的类型

    用途说明 type命令用来显示指定命令的类型.一个命令的类型可以是如下之一 alias 别名 keyword 关键字,Shell保留字 function 函数,Shell函数 builtin 内建命令 ...

  7. 《转》我眼中的C# 3.0

    本文转载自Allen Lee's Magic 缘起 每次有新技术发布时,我们总能感受到两种截然不同的情绪:一种是恐惧和抵抗,伴随着这种情绪的还有诸如"C# 2.0用的挺好的,为什么要在C# ...

  8. 安装安全狗后,MP4无法播放

  9. Apache服务器最新版下载、安装及配置(win版)

    Apache服务器最新版下载.安装及配置(win版) Apache的下载: 登录http://httpd.apache.org/download.cgi 这个地址,找到2.4.10,如下图位置:   ...

  10. 【jQuery系列之插件】jquery插件之jquery-validation

    equalTo方法: equalTo: function( value, element, param ) { // Bind to the blur event of the target in o ...