1 题目
2 Java
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
class Solution {
public ListNode deleteDuplicates(ListNode head) {
ListNode ans = new ListNode(0);
ListNode dummy = ans;
ListNode front = head;
ListNode tail;
while (front != null) {
tail = front.next;
if (tail == null || tail.val != front.val) {
ans.next = front;
ans = ans.next;
front = tail;
} else {
while (tail != null && tail.val == front.val) {
System.out.println(tail.val);
tail = tail.next;
}
front = tail;
}
}
ans.next = null;
return dummy.next;
}
}