leetcode--Remove Duplicates from Sorted List
2015-06-05 15:09
330 查看
Given a sorted linked list, delete all duplicates such that each element appear only
once.
For example,
Given
Given
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) { ListNode h = new ListNode(Integer.MAX_VALUE); h.next = head; ListNode pre = h; ListNode cur = head; while(cur!=null){ if(pre.val==cur.val){ pre.next = cur.next; }else{ pre = cur; } cur = cur.next; } return head; } }
相关文章推荐
- C++运算符重载
- APPLET运行错误Incompatible magic value问题的解决
- 从程序员到CTO的Java技术路线图
- Project Euler:Problem 44 Pentagon numbers
- PowerShell实现批量收集SCVMM中虚拟机IP-续
- Date与long转换的一个小问题
- C#中IDisposable
- .net MVC 下拉多级联动及编辑
- webAPP-meta标签
- 【openstack】openstack的调度(Scheduler)
- Android intent属性之Action
- LinearLayout显示分割线
- 时间日期对象
- 屋里多少人问题
- C++类与内存
- JDK环境变量的配置
- 在命令行下进行Oracle用户解锁
- Android 点击两次退后按钮程序退出
- Linux 文件传输客户端SSH Secure Shell Client
- 【Reverse Integer】cpp