public class Solution {
public ListNode deleteDuplication(ListNode pHead){
if(pHead==null||pHead.next==null){
return pHead;
}
ListNode head=new ListNode(-1);
head.next=pHead;
ListNode first=head;
ListNode second=pHead;
while(second.next!=null){
if(second.val==second.next.val){
first.next=second.next;
second.next=null;
second=first.next;
}else{
first=second;
second=second.next;
}
}
return head.next;
}
}
面试必考04——删除链表中重复的节点,重复节点保留一个
最新推荐文章于 2021-12-07 11:09:15 发布