JZ56 删除链表中重复的结点
删除链表中重复的结点
https://www.nowcoder.com/practice/fc533c45b73a41b0b44ccba763f866ef?tpId=13&&tqId=11209&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking
/* public class ListNode { int val; ListNode next = null; ListNode(int val) { this.val = val; } } */ public class Solution { public ListNode deleteDuplication(ListNode pHead) { ListNode first = new ListNode(-1); first.next = pHead; ListNode pre = first; ListNode cur = pHead; while(cur != null){ if (cur.next !=null && cur.val == cur.next.val){ while(cur.next !=null &&cur.val == cur.next.val){ cur = cur.next; } pre.next = cur.next; cur = cur.next; }else{ pre = cur; cur = cur.next; } } return first.next; } }