Remove duplicates from sorted list
来源:互联网 发布:淘宝网商银行是什么 编辑:程序博客网 时间:2024/06/05 21:14
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
.
Easy one, if you are not too inexperienced with linkedlist
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */public class Solution { public ListNode deleteDuplicates(ListNode head) { if(head == null) { return null; } if (head.next == null){ return head; } ListNode previous = head; while(previous!=null){ ListNode next = previous.next; if(next!=null && next.val == previous.val){ next = next.next; previous.next = next; } else{ previous = previous.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
- 恶补java(二)——java的面向对象
- 解决svn log显示no author,no date的方法之一。
- 【转】Android中对Log日志文件的分析
- JAVA基础——API(String)
- 微软云存储更换品牌 免费空间将翻番达到15GB
- Remove duplicates from sorted list
- linux【解压缩命令】
- 怎么建立基于CocoaPods的ReactiveCocoa工程
- Delphi中DataSet类型组件的Locate函数的用法
- NYOJ 638 Take it easy II
- Effective C++(19) 设计class犹如设计type
- Spring3.0+Hibernate+Atomikos集成构建JTA的分布式事务--解决多数据源跨库事务
- 马年工作 First Day
- 祝贺2014年,系统集成项目经理培训报名表