public ListNode deleteDuplication(ListNode pHead) { if(pHead==null){ return null; } ListNode preNode = null; ListNode curNode = pHead; while(curNode != null){ ListNode nextNode=curNode.next; boolean needDeleted = false; if(nextNode!=null && curNode.val == nextNode.val){ needDeleted=true; } if(!needDeleted){ preNode=curNode; curNode=curNode.next; }else { int value=curNode.val; ListNode toBeDeleted = curNode; while(toBeDeleted!=null && toBeDeleted.val == value){ nextNode=toBeDeleted.next; toBeDeleted.next=null; toBeDeleted=nextNode; } curNode=toBeDeleted; if(preNode==null){ pHead= curNode; }else{ preNode.next=curNode; } } } return pHead; }