一个排序的链表中,存在重复的结点,请删除该链表中重复的结点,重复的结点不保留,返回链表头指针。
发布日期:2021-05-11 02:21:54 浏览次数:13 分类:精选文章

本文共 1300 字,大约阅读时间需要 4 分钟。

������������������������������

���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

ListNode deleteDuplication() {

if (this.head == null) {
return null;
}
ListNode cur = this.head;
ListNode newHead = new ListNode(-1);
ListNode temp = newHead;
while (cur != null) {
// ���������������������������������������������
if (cur.next != null && cur.data == cur.next.data) {
// ������������������������
while (cur.next != null && cur.data == cur.next.data) {
cur = cur.next;
}
// ������������������������������������������������
cur = cur.next;
} else {
// ������������������������������������
temp.next = cur;
temp = temp.next;
cur = cur.next;
}
}
temp.next = null;
return newHead.next;
}

������������������������������������������������newHead������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

上一篇:java :链表的回文结构
下一篇:编写代码,以给定值x为基准将链表分割成两部分,所有小于x的结点排在大于或等于x的结点之前

发表评论

最新留言

逛到本站,mark一下
[***.202.152.39]2025年04月09日 08时23分15秒