82. Remove Duplicates from Sorted List II
来源:互联网 发布:java web视频点播系统 编辑:程序博客网 时间:2024/05/22 04:36
题目地址:remove-duplicates-from-sorted-list-ii
/** * * 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 class RemoveDuplicatesFromSortedListII {public class ListNode {int val;ListNode next;ListNode(int x) {val = x;next = null;}} public ListNode deleteDuplicates(ListNode head) { if (head == null || head.next == null) return head; ListNode result = new ListNode(-1); ListNode preNode = result; ListNode cursor = head.next; boolean isDup = false; preNode.next = head; while(cursor != null) { while(cursor != null && preNode.next.val == cursor.val) { isDup = true; cursor = cursor.next; } if (isDup) isDup = false;else preNode = preNode.next; preNode.next = cursor;if (cursor != null) cursor = cursor.next; } return result.next; }public static void main(String[] args) {// TODO Auto-generated method stub}}
0 0
- 82. Remove Duplicates from Sorted List II
- 82. Remove Duplicates from Sorted List II
- 82. Remove Duplicates from Sorted List II
- 82. Remove Duplicates from Sorted List II
- 82. Remove Duplicates from Sorted List II
- 82. Remove Duplicates from Sorted List II
- 82. Remove Duplicates from Sorted List II
- 82. Remove Duplicates from Sorted List II
- 82. Remove Duplicates from Sorted List II
- 82. Remove Duplicates from Sorted List II
- 82. Remove Duplicates from Sorted List II
- 82. Remove Duplicates from Sorted List II
- 82. Remove Duplicates from Sorted List II
- 82. Remove Duplicates from Sorted List II
- 82. Remove Duplicates from Sorted List II
- 82. Remove Duplicates from Sorted List II
- 82. Remove Duplicates from Sorted List II
- 82. Remove Duplicates from Sorted List II
- VCS使用学习
- 广州联想笔记本维修中心
- ECLIPSE android 布局页面文件出错故障排除Exception raised during rendering: java.lang.System.arraycopy([CI[CII)V
- ubuntu 12.04安装jdk
- 使用BeautifulSoup爬取“0daydown”网站的信息(1)
- 82. Remove Duplicates from Sorted List II
- POJ 3259 Wormholes(Bellman_Frod判断是否有负环)
- Leetcode: 相关子查询
- PAT1093解题报告
- 真TMD油菜(谁编的?)
- Scala-4 - 2 - Lecture 3.2 - How Classes Are Organized (20_30)
- 路径百科
- 查询yum安装到哪儿了
- div 内容设置float后,仍然高度自适应