/*
* function ListNode(x){
* this.val = x;
* this.next = null;
* }
*/
/**
*
* @param head ListNode类
* @return ListNode类
*/
function deleteDuplicates( head ) {
if(!head) return null
if(head.next == null) return head;
let startNode = null;
let temp = null;
let thead = head;
let res = new ListNode(0);
head.last = res;
res.next = head;
while(thead){
if(thead.next && thead.next.val == thead.val){
if(startNode == null){
startNode = thead.last;
}
thead = thead.next;
}else{
if(startNode != null){
startNode.next = thead.next;
thead = thead.next;
if(thead){
thead.last = startNode;}
startNode = null;
}else{
temp = thead;
thead = thead.next;
if(thead){
thead.last = temp;
}
}
}
}
return res.next
}
module.exports = {
deleteDuplicates : deleteDuplicates
};