Remove Duplicates from Sorted List II
来源:互联网 发布:php商城项目描述 编辑:程序博客网 时间:2024/06/04 08:49
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving
only distinct numbers from the original list.
For example,
Given 1->2->3->3->4->4->5, return 1->2->5.
Given 1->1->1->2->3, return 2->3.
与上一题的区别是删除重复元素,同时重复的元素不止两个。
public ListNode deleteDuplicates(ListNode head) {if(head==null||head.next==null)return head;ListNode ll=new ListNode(0);ll.next=head;ListNode newHead=ll;while(ll.next!=null&&ll.next.next!=null){if(ll.next.val==ll.next.next.val){int t=ll.next.val;while(ll.next!=null&&ll.next.val==t)ll.next=ll.next.next;}elsell=ll.next;}return newHead.next;}
0 0
- LeetCode: Remove Duplicates from Sorted List II
- Remove Duplicates from Sorted List II
- [Leetcode] Remove Duplicates from Sorted List II
- LeetCode: Remove Duplicates from Sorted List II
- [Leetcode] Remove Duplicates from Sorted List II
- [leetcode] Remove Duplicates from Sorted List II
- [LeetCode] Remove Duplicates from Sorted List II
- Remove Duplicates from Sorted List II
- [leetcode] Remove Duplicates from Sorted List II
- Remove Duplicates from Sorted List II
- Remove duplicates from sorted list II
- Remove Duplicates from Sorted List II
- Remove Duplicates from Sorted List II
- [LeetCode]Remove Duplicates from Sorted List II
- Remove Duplicates from Sorted List II
- Remove Duplicates from Sorted List II
- Remove Duplicates from Sorted List II
- [leetcode]Remove Duplicates from Sorted List II
- Static Text
- Android之 MediaPlayer播放一般音频与SoundPool播放短促的音效
- C语言经典算法100例(二)
- STM32菜鸟成长记录---系统滴答定时器(systick)应用
- 浅析layout_weight属性,gravity属性,layout_gravity属性
- Remove Duplicates from Sorted List II
- 信号量、互斥体和自旋锁
- 智慧北京2
- POJ 1635 Subway tree systems 树的Hash 或 树的最小表示法
- 南阳oj 求次数 题目1112
- EclipseLink JPA 2.1
- 哥德巴赫猜想
- IOS 去掉导航栏(UINavigationBar)下方的横线
- 多个ServletContextListener的使用