Remove Duplicates from Sorted List
来源:互联网 发布:极乐净土动作数据下载 编辑:程序博客网 时间:2024/05/19 21:19
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
.
public class ListNode {
int val;
ListNode next;
ListNode(int x) {
val = x;
next = null;
}
}
题目很简单,判断是相等的就直接指向下一个即可
public ListNode deleteDuplicates(ListNode head) {if(head==null) return null;ListNode last=head;ListNode next=head.next;while(next!=null){if(next.val==last.val){last.next=next.next;next=next.next;}else {last=next;next=next.next;}}return head;}
0 0
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove duplicates from sorted list
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- windows7 内部版本7601 此windows副本不是正版 ---解决方案
- Merge Sorted Array
- Linux 任务调度策略
- IFeatureClassManage接口更新图层全图显示时的范围
- (编译原理)C++源代码单词扫描程序(词法分析)
- Remove Duplicates from Sorted List
- #295 (div.2) E.Pluses everywhere
- Climbing Stairs
- Metaio in Unity3d 教学--- 一. 搭建环境,运行官方案例
- R语言做文本挖掘 Part2分词处理
- fullcalendar简单使用
- 2015.03.最新面试题(1)
- C++ Primer学习总结 第4章 表达式
- mybatis连接mysql数据库插入中文乱码