public class Test27 {
public class ListNode {
int val;
ListNode next;
ListNode(int x) {
val = x;
}
}
public ListNode deleteDuplicates(ListNode head) {
ListNode result = head;
while (head!=null && head.next != null) {
ListNode next = function(head);
head.next=next;
head = next;
}
return result;
}
public ListNode function(ListNode head){
if (head.next==null) {
return null;
}
if (head.next.val!=head.val) {
return head.next;
}
return function(head.next);
}
}