83. Remove Duplicates from Sorted List
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; }
* }
*/
public class Solution {
public ListNode deleteDuplicates(ListNode head) {
if(head==null||head.next==null)
return head; ListNode heads=head;
ListNode p=head.next;
while(p!=null)
{
if(p.val==heads.val)
{
p=p.next;
heads.next=p;
}
else
heads=heads.next;
}
return head;
}
}
83. Remove Duplicates from Sorted List的更多相关文章
- leetcode 203. Remove Linked List Elements 、83. Remove Duplicates from Sorted List 、82. Remove Duplicates from Sorted List II(剑指offer57 删除链表中重复的结点)
203题是在链表中删除一个固定的值,83题是在链表中删除重复的数值,但要保留一个:82也是删除重复的数值,但重复的都删除,不保留. 比如[1.2.2.3],83题要求的结果是[1.2.3],82题要求 ...
- 83. Remove Duplicates from Sorted List【easy】
83. Remove Duplicates from Sorted List[easy] Given a sorted linked list, delete all duplicates such ...
- <LeetCode OJ> 83. Remove Duplicates from Sorted List
83. Remove Duplicates from Sorted List Total Accepted: 94387 Total Submissions: 264227 Difficulty: E ...
- [LeetCode] 83. Remove Duplicates from Sorted List 移除有序链表中的重复项
Given a sorted linked list, delete all duplicates such that each element appear only once. Example 1 ...
- 【一天一道LeetCode】#83. Remove Duplicates from Sorted List
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...
- 【LeetCode】83 - Remove Duplicates from Sorted Array
Given a sorted array, remove the duplicates in place such that each element appear only once and ret ...
- 【LeetCode】83 - Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once. For examp ...
- Java [Leetcode 83]Remove Duplicates from Sorted List
题目描述: Given a sorted linked list, delete all duplicates such that each element appear only once. For ...
- leetcode修炼之路——83. Remove Duplicates from Sorted List
哈哈,我又来了.昨天发现题目太简单就没有放上来,今天来了一道有序链表的题.题目如下: Given a sorted linked list, delete all duplicates such th ...
随机推荐
- ASP.net 验证码(C#) MVC
ASP.net 验证码(C#) MVC http://blog.163.com/xu_shuhao/blog/static/5257748720101022697309/ 网站添加验证码,主要为防止机 ...
- [Js]表格排序
思路:遍历每个li,并把它们存放到数组中去,然后通过sort()方法进行排序,再插入 <body> <input type="button" value=& ...
- ASP.NET MVC学习之控制器篇(二)
原文链接:http://www.asp.net/learn/mvc/ 这篇教程探索了ASP.NET MVC控制器(controller).控制器动作(controller action)和动作结果(a ...
- 安装arbotix simulator仿真环境()
先安装rbx1功能包: cd ~/catkin_ws/src git clone https://github.com/pirobot/rbx1.git cd rbx1 git checkout in ...
- FB分别编译各个项目
FB里面有个 ActionScript模块 功能, 可以将 不同模块分别编译成一个个swf,这样会将各个独立的模块从主swf中分离出来.如果玩家没使用过这个模块,就不会加到内存中去,这样可以减少不必要 ...
- checkbox的全选、反选、删除(适配器)
package com.example.adapter; import java.util.List; import com.example.ay.R;import com.example.vo.Fl ...
- BinaryWriter
c#里的文件操作 fileInfo dir的一大堆属性不用说 地球人都知道(什么fileName,create() delete()) ,文件系统的概念很好理解的 文件读写也好理解(硬盘到内存 然后再 ...
- python——周边
Pythonic的禅意 import this python是用c语言写的.传说python不止有C语言实现,还有java实现,还有python实现的python,甚至还有js实现的python. p ...
- 《同一个类中不同方法之间的调用相关问题(省略的类名或者this)》
//同一个类中不同方法之间的调用相关问题(省略的类名或者this) class A { public void B() { System.out.println("b方法运行"); ...
- EF学习笔记(二)
DbContext 1.指定连接字符串(上一章提到) public string ConnectionStringName { get; private set; } /// <summary& ...