/*
public class ListNode {
int val;
ListNode next = null;
ListNode(int val) {
this.val = val;
}
}
*/
public class Solution {
public ListNode deleteDuplication(ListNode pHead)
{
if(pHead==null) return pHead;
ListNode head= new ListNode(0);
ListNode pre = head;
ListNode p = pHead;
pre.next = p;
while((p!=null)&&(p.next!=null))
{
if(p.next.val!=p.val)
{
p=p.next;
pre=pre.next;
}
else{
int num = p.val;
while((p!=null)&&(p.val==num))
p=p.next;
pre.next = p;
}
}
return head.next;
}
}
18、删除链表中重复的节点
最新推荐文章于 2024-02-04 12:49:15 发布