链表操作
class Solution {
public ListNode deleteDuplicates(ListNode head) {
if (head == null) return head;
if (head.next == null) return head;
ListNode now = head.next;
ListNode last = head;
while (now != null) {
while (now != null && now.val == last.val) {
now = now.next;
}
last.next = now;
last = now;
if (now != null)
now = now.next;
}
return head;
}
}
原文地址:https://www.cnblogs.com/acbingo/p/9391494.html
时间: 2024-11-05 16:40:30