113.Remove Duplicates from Sorted List II-删除排序链表中的重复数字 II(中等题)
来源:互联网 发布:三角刮刀淘宝 编辑:程序博客网 时间:2024/06/09 18:13
删除排序链表中的重复数字 II
题目
给定一个排序链表,删除所有重复的元素只留下原链表中没有重复的元素。
样例
给出 1->2->3->3->4->4->5->null,返回 1->2->5->null
给出 1->1->1->2->3->null,返回 2->3->null题解
对链表进行遍历,相邻节点不同就跳过,相同则继续遍历直至结束或找到不同节点,再进行删除操作。
/** * Definition for ListNode * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */public class Solution { /** * @param ListNode head is the head of the linked list * @return: ListNode head of the linked list */ public static ListNode deleteDuplicates(ListNode head) { ListNode result = new ListNode(1); result.next = head; ListNode pre = result; while (head != null && head.next != null) { if (head.val != head.next.val) { pre = head; head = head.next; continue; } while (head.next != null && head.val == head.next.val) { head = head.next; } pre.next = head.next; head = pre.next; } return result.next; }}
Last Update 2016.10.9
0 0
- 113.Remove Duplicates from Sorted List II-删除排序链表中的重复数字 II(中等题)
- [Lintcode]Remove Duplicates from Sorted List II 删除排序链表中的重复数字 II
- 101.Remove Duplicates from Sorted Array II-删除排序数组中的重复数字 II(容易题)
- Remove Duplicates from Sorted List II 删除链表中的元素(不保留重复)
- LeetCode 82. Remove Duplicates from Sorted List II(删除链表中的重复节点)
- 82. Remove Duplicates from Sorted List II 删除排序链表中的重复数,重复的数全部删除
- LintCode Remove Duplicates from Sorted Array II 删除排序数组中的重复数字 II
- leetCode 82.Remove Duplicates from Sorted List II (删除排序链表的重复II) 解题思路和方法
- Remove Duplicates from Sorted List II 删除链表中的所有重复节点
- 112.Remove Duplicates from Sorted List-删除排序链表中的重复元素(容易题)
- 【LeetCode-面试算法经典-Java实现】【082-Remove Duplicates from Sorted List II(排序链表中删除重复元素II)】
- 82.leetcode Remove Duplicates from Sorted List II(medium)[链表删除重复]
- LeetCdoe Remove Duplicates from Sorted List II移掉重复链表中的元素
- leetcode——Remove Duplicates from Sorted List II 删除排序字符串中重复字符(AC)
- 100.Remove Duplicates from Sorted Array-删除排序数组中的重复数字(容易题)
- LeetCode | Remove Duplicates from Sorted List II(删除链表中重复结点2)
- LintCode | Easy | 删除排序链表中的重复元素 | Remove Duplicates from Sorted List
- LeetCode: Remove Duplicates from Sorted Array II(在排序数组中删除重复元素)
- 继承特性笔记
- iOS Crash文件分析
- 71. Simplify Path
- openant
- 图论点、边集和二分图的相关概念和性质
- 113.Remove Duplicates from Sorted List II-删除排序链表中的重复数字 II(中等题)
- Eclipse配置Spket插件
- java中String类replaceAll函数的应用问题
- 给大家发一个linux下vim的很好用的配置文件
- AndroidFire,一款新闻阅读 App
- iOS判断点是否在多边形面内(高德地图开发)
- MyBatis
- HDU 4609 3-idiots(FFT优化 + 计数方法)——2013 Multi-University Training Contest 1
- HDU 4609 3-idiots(FFT优化 + 计数方法)——2013 Multi-University Training Contest 1