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. Extjs3.4--TabpanelDemo

    Ext.onReady(function () { var tab = new Ext.TabPanel({ renderTo: Ext.getBody(), height: 500 }) tab.a ...

  2. Emulator Error: Could not load OpenGLES emulation library: Could not load DLL!

    Copy the file below from SDK\tools\lib to SDK\tools. libEGL_translator.dlllibGLES_CM_translator.dlll ...

  3. PHP-004

    'URL_CASE_INSENSITIVE'  =>  true,设置为true的时候表示URL地址不区分大小写,这个也是框架在部署模式下面的默认设置. URL模式 : URL_MODEL设置 ...

  4. Dubbo(二) -- Simple Monitor

    一.简介 dubbo-monitor-simple是dubbo提供的简单监控中心,可以用来显示接口暴露,注册情况,也可以看接口的调用明细,调用时间等. Simple Monitor挂掉不会影响到Con ...

  5. 编译OSG的FreeType插件时注意的问题

    使用自己编译的freetype.lib,在编译osgdb_freetype插件项目时,报错LINK错误,找不到png的一堆函数 最简单的方式是不要使用PNG编译freetype.记住不要犯贱.

  6. PopupMenu弹出菜单

    CMenu MoviePopupMenu;//声明 MoviePopupMenu.CreatePopupMenu();//创建弹出菜单 根据对象类型增加弹出项 ) // FLASH对象 { CStri ...

  7. JQuery自定义用户控件方法汇总

    首先必用 JQuery.fn.extend方法 使用方法: jQuery.fn.extend({}); 其次 相应控件配置参数设置: jQuery.fn.extend({ uploadPreview: ...

  8. LeetCode——Add Digits

    Description: Given a non-negative integer num, repeatedly add all its digits until the result has on ...

  9. python 进行抓包嗅探

    一.绪论 最近一直想弄一个代理,并且对数据包进行解读,从而完成来往流量的嗅探.于是今天学习了一下如何使用Python抓包并进行解包. 首先要用到两个模块 dpkt(我这边ubuntu16.04 LTS ...

  10. 2.实现官网环境, 搭建HTTP服务器

    1.建立 HTTP 服务器 Node.js 是为网络而诞生的平台,但又与 ASP.PHP 有很大的不同,究竟不同在哪里呢?如果你有 PHP 开发经验,会知道在成功运行 PHP 之前先要配置一个功能强大 ...