解题思路
思路一: 迭代 快慢指针
用快指针跳过那些有重复数组,慢指针负责和快指针拼接!
public ListNode deleteDuplicates(ListNode head) {
if (head == null)
return head;
ListNode dummy = new ListNode(-1);
dummy.next = head;
ListNode slow = dummy;
ListNode fast = dummy.next;
while (fast != null){
while (fast.next != null && fast.val == fast.next.val)
fast = fast.next;
if (slow.next == fast)
slow = slow.next;
else
slow.next = fast.next;
fast = fast.next;
}
return dummy.next;
}