题解 | #删除链表中重复的结点#
删除链表中重复的结点
http://www.nowcoder.com/practice/fc533c45b73a41b0b44ccba763f866ef
public class ListNode {
int val;
ListNode next = null;
ListNode(int val) {
this.val = val;
}
}
*/
public class Solution {
public ListNode deleteDuplication(ListNode pHead) {
ListNode head = new ListNode(-1);
head.next = pHead;
ListNode cur = pHead;
ListNode pre = head;
while(cur != null){
if(cur.next == null || cur.val != cur.next.val){
pre = pre.next;
cur = cur.next;
}else{
while(cur.next != null && cur.val == cur.next.val){
cur = cur.next;
}
pre.next = cur.next;
cur = cur.next;
}
}
return head.next;
}
}