public class Test56 {
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 != null) {
if (second.next != null && second.val == second.next.val) {
while (second.next != null && second.val == second.next.val) {
second = second.next;
}
first.next = second.next;
second = first.next;
} else {
first = second;
second = second.next;
}
}
return head.next;
}
}
56 删除链表中重复的结点(重复的不保留)
最新推荐文章于 2023-08-16 17:53:21 发布