public ListNode deleteDuplication(ListNode pHead) {
if (pHead == null||pHead.next == null) {
return pHead;
}
ListNode newHead = new ListNode(-1);
newHead.next = pHead;
ListNode pre = newHead;
ListNode cur = newHead.next;
while (cur!=null) {
if (cur.next!=null&&cur.next.val == cur.val) {
while (cur.next!=null&&cur.next.val == cur.val){
cur = cur.next;
}
cur = cur.next;
pre.next = cur;
}else {
pre =cur;
cur = cur.next;
}
}
return newHead.next;
}
剑指offer之删除链表中重复节点
最新推荐文章于 2022-05-01 21:49:12 发布