JZ56 删除链表中重复的结点
删除链表中重复的结点
http://www.nowcoder.com/questionTerminal/fc533c45b73a41b0b44ccba763f866ef
public class Solution { public ListNode deleteDuplication(ListNode pHead){ if(pHead==null) return null; ListNode prev=new ListNode(pHead.val-1); prev.next=pHead; ListNode l1=prev, l2=pHead; while(l2.next!=null){ if(l2.val==l2.next.val){ ListNode l3=l2.next; while(l3!=null&&l2.val==l3.val){ l2=l2.next; l3=l3.next; } l1.next=l3; if(l3==null){ return prev.next; }else{ l2=l1.next; continue; } } l1=l1.next; l2=l2.next; } return prev.next; } }